@spritz-finance/mcp-server 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Spritz Finance
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # Spritz MCP Server
2
+
3
+ MCP server for [Spritz](https://www.spritz.finance) fiat rails — let AI agents off-ramp crypto to bank accounts.
4
+
5
+ ## What This Does
6
+
7
+ An MCP (Model Context Protocol) server that gives AI agents tools to interact with the Spritz API. Tools are derived from the [OpenAPI spec](https://sandbox.spritz.finance/openapi/json) — no hand-written schemas.
8
+
9
+ ## Installation
10
+
11
+ ### npx (recommended)
12
+
13
+ ```bash
14
+ npx @spritz-finance/mcp-server
15
+ ```
16
+
17
+ ### Global install
18
+
19
+ ```bash
20
+ npm install -g @spritz-finance/mcp-server
21
+ spritz-mcp-server
22
+ ```
23
+
24
+ ### From source
25
+
26
+ ```bash
27
+ git clone https://github.com/spritz-finance/spritz-mcp-server.git
28
+ cd spritz-mcp-server
29
+ npm install && npm run build
30
+ ```
31
+
32
+ ## Configuration
33
+
34
+ ### 1. Get Your API Key
35
+
36
+ 1. Log in to [app.spritz.finance](https://app.spritz.finance)
37
+ 2. Go to **Settings > API Keys**
38
+ 3. Create a new key
39
+
40
+ ### 2. Configure Your MCP Client
41
+
42
+ #### Claude Desktop
43
+
44
+ Add to `~/.config/claude/claude_desktop_config.json`:
45
+
46
+ ```json
47
+ {
48
+ "mcpServers": {
49
+ "spritz": {
50
+ "command": "npx",
51
+ "args": ["@spritz-finance/mcp-server"],
52
+ "env": {
53
+ "SPRITZ_API_KEY": "your-api-key"
54
+ }
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ #### Claude Code
61
+
62
+ Add to your project's `.mcp.json`:
63
+
64
+ ```json
65
+ {
66
+ "spritz": {
67
+ "command": "npx",
68
+ "args": ["@spritz-finance/mcp-server"],
69
+ "env": {
70
+ "SPRITZ_API_KEY": "your-api-key"
71
+ }
72
+ }
73
+ }
74
+ ```
75
+
76
+ #### Cursor
77
+
78
+ Add to `~/.cursor/mcp.json`:
79
+
80
+ ```json
81
+ {
82
+ "mcpServers": {
83
+ "spritz": {
84
+ "command": "npx",
85
+ "args": ["@spritz-finance/mcp-server"],
86
+ "env": {
87
+ "SPRITZ_API_KEY": "your-api-key"
88
+ }
89
+ }
90
+ }
91
+ }
92
+ ```
93
+
94
+ ## Available Tools
95
+
96
+ | Tool | Description |
97
+ |------|-------------|
98
+ | `list_bank_accounts` | List all bank accounts saved as off-ramp payment destinations |
99
+
100
+ More tools coming soon.
101
+
102
+ ## Architecture
103
+
104
+ Tools are driven by the OpenAPI spec — not hand-written. To expose a new endpoint, add one entry to `src/config.ts`:
105
+
106
+ ```ts
107
+ export const EXPOSED_TOOLS: ToolConfig[] = [
108
+ {
109
+ name: "list_bank_accounts",
110
+ operationId: "getV1Bank-accounts",
111
+ description: "List all bank accounts saved as off-ramp payment destinations.",
112
+ },
113
+ // To add a new tool, just add another entry here.
114
+ // The inputSchema, HTTP method, and path are all derived from the OpenAPI spec.
115
+ ];
116
+ ```
117
+
118
+ The server reads `openapi.json`, finds each `operationId`, extracts the JSON Schema for parameters and request bodies, and registers them as MCP tools. A generic handler dispatches tool calls to the Spritz API.
119
+
120
+ ```
121
+ openapi.json → source of truth for request/response schemas
122
+ src/config.ts → which operations to expose (cherry-pick)
123
+ src/spec.ts → reads spec, builds MCP tool definitions
124
+ src/handlers.ts → generic dispatcher (path params, query, body)
125
+ src/index.ts → MCP server + API client
126
+ ```
127
+
128
+ ## Development
129
+
130
+ ```bash
131
+ npm install
132
+ npm run dev # Watch mode
133
+ npm run build # Build
134
+ npm run inspector # MCP inspector
135
+ ```
136
+
137
+ ### Updating the OpenAPI spec
138
+
139
+ ```bash
140
+ curl -s https://sandbox.spritz.finance/openapi/json > openapi.json
141
+ ```
142
+
143
+ ## License
144
+
145
+ MIT
@@ -0,0 +1,10 @@
1
+ export declare class SpritzClient {
2
+ private apiKey;
3
+ private baseUrl;
4
+ private sessionId;
5
+ private sessionCreatedAt;
6
+ constructor();
7
+ private getSessionId;
8
+ request(method: string, path: string, body?: Record<string, unknown>): Promise<any>;
9
+ }
10
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAMA,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,gBAAgB,CAAS;;IAcjC,OAAO,CAAC,YAAY;IAQd,OAAO,CACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAyBjC"}
@@ -0,0 +1,43 @@
1
+ import { randomUUID } from "node:crypto";
2
+ const USER_AGENT = "spritz-mcp-server/0.1.0";
3
+ const ORIGIN = "https://mcp.spritz.finance";
4
+ const SESSION_TTL_MS = 15 * 60 * 1000;
5
+ export class SpritzClient {
6
+ constructor() {
7
+ this.apiKey = process.env.SPRITZ_API_KEY || "";
8
+ this.baseUrl =
9
+ process.env.SPRITZ_API_BASE_URL || "https://platform.spritz.finance";
10
+ this.sessionId = randomUUID();
11
+ this.sessionCreatedAt = Date.now();
12
+ if (!this.apiKey) {
13
+ throw new Error("SPRITZ_API_KEY must be set in environment variables");
14
+ }
15
+ }
16
+ getSessionId() {
17
+ if (Date.now() - this.sessionCreatedAt >= SESSION_TTL_MS) {
18
+ this.sessionId = randomUUID();
19
+ this.sessionCreatedAt = Date.now();
20
+ }
21
+ return this.sessionId;
22
+ }
23
+ async request(method, path, body) {
24
+ const url = `${this.baseUrl}${path}`;
25
+ const response = await fetch(url, {
26
+ method,
27
+ headers: {
28
+ Authorization: `Bearer ${this.apiKey}`,
29
+ "Content-Type": "application/json",
30
+ "User-Agent": USER_AGENT,
31
+ Origin: ORIGIN,
32
+ "session-id": this.getSessionId(),
33
+ },
34
+ ...(body ? { body: JSON.stringify(body) } : {}),
35
+ });
36
+ if (!response.ok) {
37
+ const errorText = await response.text();
38
+ throw new Error(`Spritz API error: ${response.status} ${response.statusText} - ${errorText}`);
39
+ }
40
+ return response.json();
41
+ }
42
+ }
43
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,UAAU,GAAG,yBAAyB,CAAC;AAC7C,MAAM,MAAM,GAAG,4BAA4B,CAAC;AAC5C,MAAM,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEtC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EH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CACb,qBAAqB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,MAAM,SAAS,EAAE,CAC7E,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Which OpenAPI operations to expose as MCP tools.
3
+ *
4
+ * To add a new tool: add an entry here with the operationId from openapi.json.
5
+ * The inputSchema and HTTP details are derived from the spec automatically.
6
+ */
7
+ export interface ToolConfig {
8
+ /** MCP tool name (what the AI agent sees) */
9
+ name: string;
10
+ /** operationId from the OpenAPI spec */
11
+ operationId: string;
12
+ /** Override the spec's summary/description */
13
+ description?: string;
14
+ }
15
+ export declare const EXPOSED_TOOLS: ToolConfig[];
16
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,aAAa,EAAE,UAAU,EAMrC,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Which OpenAPI operations to expose as MCP tools.
3
+ *
4
+ * To add a new tool: add an entry here with the operationId from openapi.json.
5
+ * The inputSchema and HTTP details are derived from the spec automatically.
6
+ */
7
+ export const EXPOSED_TOOLS = [
8
+ {
9
+ name: "list_bank_accounts",
10
+ operationId: "getV1Bank-accounts",
11
+ description: "List all bank accounts saved as off-ramp payment destinations.",
12
+ },
13
+ ];
14
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,MAAM,CAAC,MAAM,aAAa,GAAiB;IACzC;QACE,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EAAE,oBAAoB;QACjC,WAAW,EAAE,gEAAgE;KAC9E;CACF,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { CallToolRequest } from "@modelcontextprotocol/sdk/types.js";
2
+ import type { SpritzClient } from "./client.js";
3
+ import type { ResolvedOperation } from "./spec.js";
4
+ /**
5
+ * Generic handler that dispatches MCP tool calls to the Spritz API
6
+ * based on resolved OpenAPI operations.
7
+ */
8
+ export declare function handleToolCall(request: CallToolRequest, operations: ResolvedOperation[], client: SpritzClient): Promise<{
9
+ content: {
10
+ type: "text";
11
+ text: string;
12
+ }[];
13
+ isError: boolean;
14
+ } | {
15
+ content: {
16
+ type: "text";
17
+ text: string;
18
+ }[];
19
+ isError?: undefined;
20
+ }>;
21
+ //# sourceMappingURL=handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD;;;GAGG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,iBAAiB,EAAE,EAC/B,MAAM,EAAE,YAAY;;;;;;;;;;;;GAoDrB"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Generic handler that dispatches MCP tool calls to the Spritz API
3
+ * based on resolved OpenAPI operations.
4
+ */
5
+ export async function handleToolCall(request, operations, client) {
6
+ const { name, arguments: args } = request.params;
7
+ const op = operations.find((o) => o.config.name === name);
8
+ if (!op) {
9
+ return {
10
+ content: [{ type: "text", text: `Error: Unknown tool "${name}"` }],
11
+ isError: true,
12
+ };
13
+ }
14
+ try {
15
+ // Substitute path parameters, e.g. /v1/bank-accounts/{accountId}
16
+ let path = op.path;
17
+ const queryParams = {};
18
+ const bodyParams = {};
19
+ // Separate args into path params, query params, and body params
20
+ const pathParamNames = [...path.matchAll(/\{(\w+)\}/g)].map((m) => m[1]);
21
+ for (const [key, value] of Object.entries(args ?? {})) {
22
+ if (pathParamNames.includes(key)) {
23
+ path = path.replace(`{${key}}`, encodeURIComponent(String(value)));
24
+ }
25
+ else if (op.method === "get" || op.method === "delete") {
26
+ queryParams[key] = String(value);
27
+ }
28
+ else {
29
+ bodyParams[key] = value;
30
+ }
31
+ }
32
+ // Build query string for GET/DELETE
33
+ const qs = new URLSearchParams(queryParams).toString();
34
+ if (qs)
35
+ path = `${path}?${qs}`;
36
+ // Make the request
37
+ const result = await client.request(op.method.toUpperCase(), path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined);
38
+ return {
39
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
40
+ };
41
+ }
42
+ catch (error) {
43
+ const message = error instanceof Error ? error.message : "Unknown error";
44
+ return {
45
+ content: [{ type: "text", text: `Error: ${message}` }],
46
+ isError: true,
47
+ };
48
+ }
49
+ }
50
+ //# sourceMappingURL=handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/handlers.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAwB,EACxB,UAA+B,EAC/B,MAAoB;IAEpB,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAEjD,MAAM,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,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QACvD,IAAI,EAAE;YAAE,IAAI,GAAG,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC;QAE/B,mBAAmB;QACnB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CACjC,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,EACvB,IAAI,EACJ,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAC5D,CAAC;QAEF,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;SAC5E,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;QACzE,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,UAAU,OAAO,EAAE,EAAE,CAAC;YAC/D,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
5
+ import dotenv from "dotenv";
6
+ import { EXPOSED_TOOLS } from "./config.js";
7
+ import { loadSpec, resolveTools, toMcpTools } from "./spec.js";
8
+ import { handleToolCall } from "./handlers.js";
9
+ import { SpritzClient } from "./client.js";
10
+ dotenv.config();
11
+ // ============================================================================
12
+ // Server
13
+ // ============================================================================
14
+ async function main() {
15
+ if (!process.env.SPRITZ_API_KEY) {
16
+ console.error("Missing SPRITZ_API_KEY in environment variables.");
17
+ console.error("Create a .env file based on .env.example with your Spritz API key.");
18
+ process.exit(1);
19
+ }
20
+ // Load OpenAPI spec and resolve selected operations
21
+ const spec = loadSpec();
22
+ const operations = resolveTools(spec, EXPOSED_TOOLS);
23
+ const mcpTools = toMcpTools(operations);
24
+ const client = new SpritzClient();
25
+ const server = new Server({ name: "spritz-mcp-server", version: "0.1.0" }, { capabilities: { tools: {} } });
26
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
27
+ tools: mcpTools,
28
+ }));
29
+ server.setRequestHandler(CallToolRequestSchema, async (request) => handleToolCall(request, operations, client));
30
+ const transport = new StdioServerTransport();
31
+ await server.connect(transport);
32
+ console.error("Spritz MCP Server is running via stdio");
33
+ }
34
+ main().catch((error) => {
35
+ console.error("Fatal error:", error);
36
+ process.exit(1);
37
+ });
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa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ACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,60 @@
1
+ import type { ToolConfig } from "./config.js";
2
+ export interface ResolvedOperation {
3
+ /** HTTP method (lowercase) */
4
+ method: string;
5
+ /** URL path template, e.g. /v1/bank-accounts/{accountId} */
6
+ path: string;
7
+ /** JSON Schema for the MCP tool's input */
8
+ inputSchema: Record<string, unknown>;
9
+ /** The original tool config entry */
10
+ config: ToolConfig;
11
+ /** Summary from the spec (fallback for description) */
12
+ summary: string;
13
+ }
14
+ export interface OpenAPIOperation {
15
+ operationId?: string;
16
+ summary?: string;
17
+ description?: string;
18
+ parameters?: OpenAPIParameter[];
19
+ requestBody?: {
20
+ content?: Record<string, {
21
+ schema?: Record<string, unknown>;
22
+ }>;
23
+ };
24
+ }
25
+ export interface OpenAPIParameter {
26
+ name: string;
27
+ in: string;
28
+ required?: boolean;
29
+ description?: string;
30
+ schema?: Record<string, unknown>;
31
+ }
32
+ export declare function loadSpec(): Record<string, unknown>;
33
+ /**
34
+ * Walk every path+method in the spec and index by operationId.
35
+ */
36
+ export declare function indexOperations(spec: Record<string, unknown>): Map<string, {
37
+ method: string;
38
+ path: string;
39
+ op: OpenAPIOperation;
40
+ }>;
41
+ /**
42
+ * Build a JSON Schema inputSchema for an MCP tool from an OpenAPI operation.
43
+ *
44
+ * Merges path params, query params, and request body into a single flat object schema.
45
+ */
46
+ export declare function buildInputSchema(op: OpenAPIOperation): Record<string, unknown>;
47
+ /**
48
+ * Resolve the selected tool configs against the OpenAPI spec.
49
+ * Throws if an operationId is not found.
50
+ */
51
+ export declare function resolveTools(spec: Record<string, unknown>, tools: ToolConfig[]): ResolvedOperation[];
52
+ /**
53
+ * Convert resolved operations to MCP tool definitions.
54
+ */
55
+ export declare function toMcpTools(operations: ResolvedOperation[]): {
56
+ name: string;
57
+ description: string;
58
+ inputSchema: Record<string, unknown>;
59
+ }[];
60
+ //# sourceMappingURL=spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spec.d.ts","sourceRoot":"","sources":["../../src/spec.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAM9C,MAAM,WAAW,iBAAiB;IAChC,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,qCAAqC;IACrC,MAAM,EAAE,UAAU,CAAC;IACnB,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAChC,WAAW,CAAC,EAAE;QACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,CAAC,CAAC;KAChE,CAAC;CACH;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAMD,wBAAgB,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIlD;AAMD;;GAEG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,GAAG,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,gBAAgB,CAAA;CAAE,CAAC,CAiBrE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAqC9E;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,EAAE,UAAU,EAAE,GAClB,iBAAiB,EAAE,CAuBrB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,iBAAiB,EAAE;;;;IAMzD"}
@@ -0,0 +1,108 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { resolve, dirname } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ // ============================================================================
5
+ // Spec loading
6
+ // ============================================================================
7
+ export function loadSpec() {
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+ const specPath = resolve(__dirname, "../../openapi.json");
10
+ return JSON.parse(readFileSync(specPath, "utf-8"));
11
+ }
12
+ // ============================================================================
13
+ // Operation resolution
14
+ // ============================================================================
15
+ /**
16
+ * Walk every path+method in the spec and index by operationId.
17
+ */
18
+ export function indexOperations(spec) {
19
+ const paths = spec["paths"];
20
+ if (!paths)
21
+ return new Map();
22
+ const index = new Map();
23
+ for (const [path, methods] of Object.entries(paths)) {
24
+ for (const [method, opOrRef] of Object.entries(methods)) {
25
+ if (typeof opOrRef !== "object" || opOrRef === null)
26
+ continue;
27
+ const op = opOrRef;
28
+ if (op.operationId) {
29
+ index.set(op.operationId, { method, path, op });
30
+ }
31
+ }
32
+ }
33
+ return index;
34
+ }
35
+ /**
36
+ * Build a JSON Schema inputSchema for an MCP tool from an OpenAPI operation.
37
+ *
38
+ * Merges path params, query params, and request body into a single flat object schema.
39
+ */
40
+ export function buildInputSchema(op) {
41
+ const properties = {};
42
+ const required = [];
43
+ // Path and query parameters
44
+ for (const param of op.parameters ?? []) {
45
+ if (param.in === "path" || param.in === "query") {
46
+ properties[param.name] = {
47
+ ...param.schema,
48
+ ...(param.description ? { description: param.description } : {}),
49
+ };
50
+ if (param.required || param.in === "path") {
51
+ required.push(param.name);
52
+ }
53
+ }
54
+ }
55
+ // Request body (JSON only)
56
+ const bodySchema = op.requestBody?.content?.["application/json"]?.schema;
57
+ if (bodySchema && typeof bodySchema === "object" && "properties" in bodySchema) {
58
+ const bodyProps = bodySchema["properties"];
59
+ if (bodyProps) {
60
+ for (const [key, value] of Object.entries(bodyProps)) {
61
+ properties[key] = value;
62
+ }
63
+ }
64
+ const bodyRequired = bodySchema["required"];
65
+ if (bodyRequired) {
66
+ required.push(...bodyRequired);
67
+ }
68
+ }
69
+ return {
70
+ type: "object",
71
+ properties,
72
+ required,
73
+ };
74
+ }
75
+ /**
76
+ * Resolve the selected tool configs against the OpenAPI spec.
77
+ * Throws if an operationId is not found.
78
+ */
79
+ export function resolveTools(spec, tools) {
80
+ const index = indexOperations(spec);
81
+ const resolved = [];
82
+ for (const config of tools) {
83
+ const entry = index.get(config.operationId);
84
+ if (!entry) {
85
+ throw new Error(`operationId "${config.operationId}" not found in OpenAPI spec. ` +
86
+ `Available: ${[...index.keys()].join(", ")}`);
87
+ }
88
+ resolved.push({
89
+ method: entry.method,
90
+ path: entry.path,
91
+ inputSchema: buildInputSchema(entry.op),
92
+ config,
93
+ summary: entry.op.summary ?? "",
94
+ });
95
+ }
96
+ return resolved;
97
+ }
98
+ /**
99
+ * Convert resolved operations to MCP tool definitions.
100
+ */
101
+ export function toMcpTools(operations) {
102
+ return operations.map((op) => ({
103
+ name: op.config.name,
104
+ description: op.config.description ?? op.summary,
105
+ inputSchema: op.inputSchema,
106
+ }));
107
+ }
108
+ //# sourceMappingURL=spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spec.js","sourceRoot":"","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