@pmxt/mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Entry point for the PMXT MCP server.
4
+ *
5
+ * Usage:
6
+ * npx @pmxt/mcp # hosted mode (needs PMXT_API_KEY)
7
+ * PMXT_API_KEY=pmxt_live_... npx @pmxt/mcp
8
+ * PMXT_API_URL=http://localhost:3847 npx @pmxt/mcp # sidecar mode
9
+ */
10
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Entry point for the PMXT MCP server.
4
+ *
5
+ * Usage:
6
+ * npx @pmxt/mcp # hosted mode (needs PMXT_API_KEY)
7
+ * PMXT_API_KEY=pmxt_live_... npx @pmxt/mcp
8
+ * PMXT_API_URL=http://localhost:3847 npx @pmxt/mcp # sidecar mode
9
+ */
10
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
11
+ import { loadConfig } from "./config.js";
12
+ import { createServer } from "./server.js";
13
+ const config = loadConfig();
14
+ const server = createServer(config);
15
+ const transport = new StdioServerTransport();
16
+ await server.connect(transport);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * MCP server for PMXT.
3
+ *
4
+ * Registers one tool per PMXT REST API endpoint. Each tool call is
5
+ * translated into an HTTP POST to the PMXT API (hosted or sidecar).
6
+ */
7
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
8
+ import type { Config } from "./config.js";
9
+ export declare function createServer(config: Config): Server;
package/dist/server.js ADDED
@@ -0,0 +1,93 @@
1
+ /**
2
+ * MCP server for PMXT.
3
+ *
4
+ * Registers one tool per PMXT REST API endpoint. Each tool call is
5
+ * translated into an HTTP POST to the PMXT API (hosted or sidecar).
6
+ */
7
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
8
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
9
+ import { TOOLS } from "./generated/tools.js";
10
+ import { callPmxtApi } from "./client.js";
11
+ import { reconstructArgs } from "./args.js";
12
+ const INSTRUCTIONS = `PMXT is a unified API for prediction markets (Polymarket, Kalshi, Limitless, and more). \
13
+ Same methods, same response shape, regardless of venue.
14
+
15
+ SETUP: Get an API key at pmxt.dev/dashboard. Set PMXT_API_KEY in your environment.
16
+
17
+ IMPORTANT RULES:
18
+ - NEVER place orders (createOrder, submitOrder) without explicit user confirmation. \
19
+ These spend real money. Always show the user the order details (venue, market, side, price, amount) and wait for approval.
20
+ - cancelOrder also requires user confirmation.
21
+ - Read-only tools (fetchMarkets, fetchOrderBook, etc.) are safe to call freely.
22
+ - Venue credentials (privateKey, apiKey) are sensitive. Never log or display them.
23
+
24
+ WORKFLOW:
25
+ 1. Use fetchMarkets or fetchEvents to discover markets (use the "query" param for search).
26
+ 2. Use fetchOrderBook to check liquidity and prices.
27
+ 3. Use getExecutionPrice to quote a trade before placing it.
28
+ 4. Use buildOrder to preview, then submitOrder to execute (with user approval).
29
+
30
+ The "exchange" param is required on every call. Options: polymarket, kalshi, limitless, probable, etc.`;
31
+ export function createServer(config) {
32
+ const server = new Server({ name: "@pmxt/mcp", version: "0.1.0" }, {
33
+ capabilities: { tools: {} },
34
+ instructions: INSTRUCTIONS,
35
+ });
36
+ const toolMap = new Map();
37
+ for (const tool of TOOLS) {
38
+ toolMap.set(tool.name, tool);
39
+ }
40
+ server.setRequestHandler(ListToolsRequestSchema, () => ({
41
+ tools: TOOLS.map((t) => ({
42
+ name: t.name,
43
+ description: t.description,
44
+ inputSchema: t.inputSchema,
45
+ annotations: t.annotations,
46
+ })),
47
+ }));
48
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
49
+ const { name, arguments: rawArgs } = request.params;
50
+ const def = toolMap.get(name);
51
+ if (!def) {
52
+ return {
53
+ content: [{ type: "text", text: `Unknown tool: ${name}` }],
54
+ isError: true,
55
+ };
56
+ }
57
+ const input = (rawArgs ?? {});
58
+ const exchange = input.exchange;
59
+ if (!exchange) {
60
+ return {
61
+ content: [
62
+ { type: "text", text: "Missing required parameter: exchange" },
63
+ ],
64
+ isError: true,
65
+ };
66
+ }
67
+ // Separate credentials from the rest of the input
68
+ const credentials = input.credentials;
69
+ const { exchange: _ex, credentials: _cred, ...rest } = input;
70
+ const args = reconstructArgs(rest, def.args);
71
+ try {
72
+ const result = await callPmxtApi(config, {
73
+ exchange,
74
+ method: def.method,
75
+ args,
76
+ credentials,
77
+ });
78
+ return {
79
+ content: [
80
+ { type: "text", text: JSON.stringify(result, null, 2) },
81
+ ],
82
+ };
83
+ }
84
+ catch (error) {
85
+ const message = error instanceof Error ? error.message : String(error);
86
+ return {
87
+ content: [{ type: "text", text: `PMXT API error: ${message}` }],
88
+ isError: true,
89
+ };
90
+ }
91
+ });
92
+ return server;
93
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@pmxt/mcp",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for PMXT - the unified prediction market API",
5
+ "type": "module",
6
+ "bin": {
7
+ "pmxt-mcp": "./dist/index.js"
8
+ },
9
+ "main": "./dist/index.js",
10
+ "files": [
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "clean": "rm -rf dist",
16
+ "generate": "node scripts/generate-tools.cjs",
17
+ "prebuild": "npm run clean",
18
+ "build": "tsc",
19
+ "prepack": "npm run build"
20
+ },
21
+ "keywords": [
22
+ "mcp",
23
+ "prediction-markets",
24
+ "polymarket",
25
+ "kalshi",
26
+ "trading",
27
+ "ai-agent",
28
+ "llm",
29
+ "model-context-protocol"
30
+ ],
31
+ "dependencies": {
32
+ "@modelcontextprotocol/sdk": "^1.12.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^20.0.0",
36
+ "js-yaml": "^4.1.0",
37
+ "typescript": "^5.0.0"
38
+ }
39
+ }