Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,21 @@ Create a `.cursor/mcp.json` file in your project root with the following content

</details>

You can also run MCP servers as a standalone binary with no additional dependencies. You must pull these binaries from available Github releases:
You can also run MCP servers as a standalone binary with no additional dependencies. Download the binaries from the Polar SDK GitHub releases:

```bash
curl -L -o mcp-server \
https://github.com/{org}/{repo}/releases/download/{tag}/mcp-server-bun-darwin-arm64 && \
https://github.com/polarsource/polar-js/releases/download/{tag}/mcp-server-bun-darwin-arm64 && \
chmod +x mcp-server
```

If the repo is a private repo you must add your Github PAT to download a release `-H "Authorization: Bearer {GITHUB_PAT}"`.
Replace `{tag}` with the desired release tag. See available tags at https://github.com/polarsource/polar-js/releases. If the repo is private, add your GitHub PAT header: `-H "Authorization: Bearer {GITHUB_PAT}"`.


```json
{
"mcpServers": {
"Todos": {
"Polar": {
"command": "./DOWNLOAD/PATH/mcp-server",
"args": [
"start"
Expand Down
9 changes: 6 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ This directory contains example scripts demonstrating how to use the @polar-sh/s

## Running the Examples

To run an example file from the examples directory:
To run an example from this directory:

```bash
npm run build && npx tsx example.ts
npm run build && npx tsx organizationsList.example.ts
```

Available examples:
- organizationsList.example.ts — lists organizations using the SDK
- webhookExpress.example.ts — minimal Express server validating Polar webhooks

## Creating new examples

Duplicate an existing example file, they won't be overwritten by the generation process.


10 changes: 7 additions & 3 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
"scripts": {
"build:parent": "cd .. && npm i && npm run build && cd -",
"build:examples": "npm i",
"build": "npm run build:parent && npm run build:examples"
"build": "npm run build:parent && npm run build:examples",
"start:orgs": "npm run build && npx tsx organizationsList.example.ts",
"start:webhooks": "npm run build && npx tsx webhookExpress.example.ts"
},
"devDependencies": {
"@types/node": "^20.0.0",
"dotenv": "^16.4.5",
"tsx": "^4.19.2"
"tsx": "^4.19.2",
"express": "^4.21.2",
"@types/express": "^4.17.21"
},
"dependencies": {
"@polar-sh/sdk": "file:.."
}
}
}
44 changes: 44 additions & 0 deletions examples/webhookExpress.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Example: Minimal Express server validating Polar webhooks
*
* To run from the examples directory:
* npm run build && npx tsx webhookExpress.example.ts
*/

import dotenv from "dotenv";
dotenv.config();

import express, { Request, Response } from "express";
import { validateEvent, WebhookVerificationError } from "@polar-sh/sdk/webhooks";

const app = express();

// Use raw body for signature verification
app.post("/webhook", express.raw({ type: "application/json" }), (req: Request, res: Response) => {
try {
const secret = process.env["POLAR_WEBHOOK_SECRET"] ?? "";
if (!secret) {
console.warn("POLAR_WEBHOOK_SECRET is not set; refusing to validate requests.");
return res.status(500).send("");
}

const event = validateEvent(req.body, req.headers as Record<string, string>, secret);

// TODO: Handle the event by type if desired
console.log("Received webhook:", event.type);

return res.status(202).send("");
} catch (error) {
if (error instanceof WebhookVerificationError) {
return res.status(403).send("");
}
console.error(error);
return res.status(500).send("");
}
});

const port = Number(process.env["PORT"] ?? 3000);
app.listen(port, () => {
console.log(`Webhook server listening on http://localhost:${port}`);
});