|
| 1 | +exports['McpServer updateContent updates the version 1'] = ` |
| 2 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 3 | +
|
| 4 | +import { Server } from '@modelcontextprotocol/sdk/server/index.js'; |
| 5 | +import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; |
| 6 | +import { tools, handlers, HandlerFunction } from './tools'; |
| 7 | +import { CallToolRequestSchema, ListToolsRequestSchema, Tool } from '@modelcontextprotocol/sdk/types.js'; |
| 8 | +import ModernTreasury from 'modern-treasury'; |
| 9 | +export { tools, handlers } from './tools'; |
| 10 | +
|
| 11 | +// Create server instance |
| 12 | +export const server = new McpServer( |
| 13 | + { |
| 14 | + name: 'modern_treasury_api', |
| 15 | + version: '2.36.1', |
| 16 | + }, |
| 17 | + { |
| 18 | + capabilities: { |
| 19 | + tools: {}, |
| 20 | + }, |
| 21 | + }, |
| 22 | +); |
| 23 | +
|
| 24 | +/** |
| 25 | + * Initializes the provided MCP Server with the given tools and handlers. |
| 26 | + * If not provided, the default client, tools and handlers will be used. |
| 27 | + */ |
| 28 | +export function init(params: { |
| 29 | + server: Server | McpServer; |
| 30 | + client?: ModernTreasury; |
| 31 | + tools?: Tool[]; |
| 32 | + handlers?: Record<string, HandlerFunction>; |
| 33 | +}) { |
| 34 | + const server = params.server instanceof McpServer ? params.server.server : params.server; |
| 35 | + const providedTools = params.tools || tools; |
| 36 | + const providedHandlers = params.handlers || handlers; |
| 37 | + const client = params.client || new ModernTreasury({}); |
| 38 | +
|
| 39 | + server.setRequestHandler(ListToolsRequestSchema, async () => { |
| 40 | + return { |
| 41 | + tools: providedTools, |
| 42 | + }; |
| 43 | + }); |
| 44 | +
|
| 45 | + server.setRequestHandler(CallToolRequestSchema, async (request) => { |
| 46 | + const { name, arguments: args } = request.params; |
| 47 | +
|
| 48 | + const handler = providedHandlers[name]; |
| 49 | + if (!handler) { |
| 50 | + throw new Error(\`Unknown tool: \${name}\`); |
| 51 | + } |
| 52 | +
|
| 53 | + return executeHandler(handler, client, args); |
| 54 | + }); |
| 55 | +} |
| 56 | +
|
| 57 | +/** |
| 58 | + * Runs the provided handler with the given client and arguments. |
| 59 | + */ |
| 60 | +export async function executeHandler( |
| 61 | + handler: HandlerFunction, |
| 62 | + client: ModernTreasury, |
| 63 | + args: Record<string, unknown> | undefined, |
| 64 | +) { |
| 65 | + const result = await handler(client, args || {}); |
| 66 | + return { |
| 67 | + content: [ |
| 68 | + { |
| 69 | + type: 'text', |
| 70 | + text: JSON.stringify(result, null, 2), |
| 71 | + }, |
| 72 | + ], |
| 73 | + }; |
| 74 | +} |
| 75 | +
|
| 76 | +export const readEnv = (env: string): string => { |
| 77 | + let envValue = undefined; |
| 78 | + if (typeof (globalThis as any).process !== 'undefined') { |
| 79 | + envValue = (globalThis as any).process.env?.[env]?.trim(); |
| 80 | + } else if (typeof (globalThis as any).Deno !== 'undefined') { |
| 81 | + envValue = (globalThis as any).Deno.env?.get?.(env)?.trim(); |
| 82 | + } |
| 83 | + if (envValue === undefined) { |
| 84 | + throw new Error(\`Environment variable \${env} is not set\`); |
| 85 | + } |
| 86 | + return envValue; |
| 87 | +}; |
| 88 | +` |
0 commit comments