diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 9022474..83f9eb8 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.2.3" + ".": "4.3.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index ae58e82..98b9d0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,35 @@ # Changelog +## 4.3.0 (2025-12-06) + +Full Changelog: [v4.2.3...v4.3.0](https://github.com/beeper/desktop-api-js/compare/v4.2.3...v4.3.0) + +### Features + +* **mcp:** add detail field to docs search tool ([94efb53](https://github.com/beeper/desktop-api-js/commit/94efb539eb6279bd5e8076e9652aaac821d7e465)) +* **mcp:** add typescript check to code execution tool ([dd5606a](https://github.com/beeper/desktop-api-js/commit/dd5606aeb6f72a2b7383a7a52d47a3786adb7fe8)) +* **mcp:** handle code mode calls in the Stainless API ([0583d4a](https://github.com/beeper/desktop-api-js/commit/0583d4a1b97f825d9c3e76c9eae155d09e108f4c)) +* **mcp:** return logs on code tool errors ([d635e28](https://github.com/beeper/desktop-api-js/commit/d635e28ce32796e0e71b8ee21a579fbca061f1f5)) + + +### Bug Fixes + +* **mcp:** correct code tool API endpoint ([e4d8fd3](https://github.com/beeper/desktop-api-js/commit/e4d8fd374547a678ae125358bcbc52f092df00cb)) +* **mcp:** return correct lines on typescript errors ([2670800](https://github.com/beeper/desktop-api-js/commit/267080003620b463563fbe0fa1808a12d471a692)) +* **mcp:** return tool execution error on api error ([7886dae](https://github.com/beeper/desktop-api-js/commit/7886dae7ae5da785ef4bea988f253e35007ee16a)) +* **mcp:** return tool execution error on jq failure ([cadbf31](https://github.com/beeper/desktop-api-js/commit/cadbf3111d4aff52467527cbad99abba90164cc8)) + + +### Chores + +* **client:** fix logger property type ([6ecc636](https://github.com/beeper/desktop-api-js/commit/6ecc636c5e0c2a2aeaed7da6e57a1663b3d711e7)) +* **internal:** codegen related update ([a44f1e6](https://github.com/beeper/desktop-api-js/commit/a44f1e6e5afca1513ef3484f853fe45599e4a1ee)) +* **internal:** codegen related update ([6148100](https://github.com/beeper/desktop-api-js/commit/61481002797da513cdf64b33161fb6399de710aa)) +* **internal:** upgrade eslint ([7256acf](https://github.com/beeper/desktop-api-js/commit/7256acf2e8fdd02aae2b169e15547fddb10fb250)) +* **mcp:** clarify http auth error ([79374fd](https://github.com/beeper/desktop-api-js/commit/79374fd11b48ad2c96097184b492b6f6f7710593)) +* **mcp:** upgrade jq-web ([298fec2](https://github.com/beeper/desktop-api-js/commit/298fec2720697f7c36077104a2325ecd05d9a839)) +* use latest @modelcontextprotocol/sdk ([6400f79](https://github.com/beeper/desktop-api-js/commit/6400f79bf4d6fd5bc46a11ccf2336327910a39e9)) + ## 4.2.3 (2025-11-08) Full Changelog: [v4.2.2...v4.2.3](https://github.com/beeper/desktop-api-js/compare/v4.2.2...v4.2.3) diff --git a/package.json b/package.json index ed69a18..a30d699 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@beeper/desktop-api", - "version": "4.2.3", + "version": "4.3.0", "description": "The official TypeScript library for the Beeper Desktop API", "author": "Beeper Desktop ", "types": "dist/index.d.ts", @@ -35,7 +35,7 @@ "@types/node": "^20.17.6", "@typescript-eslint/eslint-plugin": "8.31.1", "@typescript-eslint/parser": "8.31.1", - "eslint": "^9.20.1", + "eslint": "^9.39.1", "eslint-plugin-prettier": "^5.4.1", "eslint-plugin-unused-imports": "^4.1.4", "iconv-lite": "^0.6.3", diff --git a/packages/mcp-server/package.json b/packages/mcp-server/package.json index 529f4fe..5f3235c 100644 --- a/packages/mcp-server/package.json +++ b/packages/mcp-server/package.json @@ -1,6 +1,6 @@ { "name": "@beeper/desktop-mcp", - "version": "4.2.3", + "version": "4.3.0", "description": "The official MCP Server for the Beeper Desktop API", "author": "Beeper Desktop ", "types": "dist/index.d.ts", @@ -32,13 +32,13 @@ "dependencies": { "@beeper/desktop-api": "file:../../dist/", "@cloudflare/cabidela": "^0.2.4", - "@modelcontextprotocol/sdk": "^1.11.5", + "@modelcontextprotocol/sdk": "^1.24.0", "@valtown/deno-http-worker": "^0.0.21", "cors": "^2.8.5", "date-fns": "^4.1.0", "express": "^5.1.0", "fuse.js": "^7.1.0", - "jq-web": "https://github.com/stainless-api/jq-web/releases/download/v0.8.6/jq-web.tar.gz", + "jq-web": "https://github.com/stainless-api/jq-web/releases/download/v0.8.8/jq-web.tar.gz", "qs": "^6.14.0", "typescript": "5.8.3", "yargs": "^17.7.2", diff --git a/packages/mcp-server/src/code-tool-paths.cts b/packages/mcp-server/src/code-tool-paths.cts deleted file mode 100644 index 15ce7f5..0000000 --- a/packages/mcp-server/src/code-tool-paths.cts +++ /dev/null @@ -1,3 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -export const workerPath = require.resolve('./code-tool-worker.mjs'); diff --git a/packages/mcp-server/src/code-tool-types.ts b/packages/mcp-server/src/code-tool-types.ts index 8866460..42c8bb7 100644 --- a/packages/mcp-server/src/code-tool-types.ts +++ b/packages/mcp-server/src/code-tool-types.ts @@ -11,4 +11,8 @@ export type WorkerSuccess = { logLines: string[]; errLines: string[]; }; -export type WorkerError = { message: string | undefined }; +export type WorkerError = { + message: string | undefined; + logLines: string[]; + errLines: string[]; +}; diff --git a/packages/mcp-server/src/code-tool-worker.ts b/packages/mcp-server/src/code-tool-worker.ts deleted file mode 100644 index aee55b5..0000000 --- a/packages/mcp-server/src/code-tool-worker.ts +++ /dev/null @@ -1,209 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -import util from 'node:util'; - -import Fuse from 'fuse.js'; -import ts from 'typescript'; - -import { WorkerInput, WorkerSuccess, WorkerError } from './code-tool-types'; -import { BeeperDesktop } from '@beeper/desktop-api'; - -function getRunFunctionNode( - code: string, -): ts.FunctionDeclaration | ts.FunctionExpression | ts.ArrowFunction | null { - const sourceFile = ts.createSourceFile('code.ts', code, ts.ScriptTarget.Latest, true); - - for (const statement of sourceFile.statements) { - // Check for top-level function declarations - if (ts.isFunctionDeclaration(statement)) { - if (statement.name?.text === 'run') { - return statement; - } - } - - // Check for variable declarations: const run = () => {} or const run = function() {} - if (ts.isVariableStatement(statement)) { - for (const declaration of statement.declarationList.declarations) { - if (ts.isIdentifier(declaration.name) && declaration.name.text === 'run') { - // Check if it's initialized with a function - if ( - declaration.initializer && - (ts.isFunctionExpression(declaration.initializer) || ts.isArrowFunction(declaration.initializer)) - ) { - return declaration.initializer; - } - } - } - } - } - - return null; -} - -const fuse = new Fuse( - [ - 'client.focus', - 'client.search', - 'client.accounts.list', - 'client.accounts.contacts.search', - 'client.chats.archive', - 'client.chats.create', - 'client.chats.list', - 'client.chats.retrieve', - 'client.chats.search', - 'client.chats.reminders.create', - 'client.chats.reminders.delete', - 'client.messages.list', - 'client.messages.search', - 'client.messages.send', - 'client.assets.download', - ], - { threshold: 1, shouldSort: true }, -); - -function getMethodSuggestions(fullyQualifiedMethodName: string): string[] { - return fuse - .search(fullyQualifiedMethodName) - .map(({ item }) => item) - .slice(0, 5); -} - -const proxyToObj = new WeakMap(); -const objToProxy = new WeakMap(); - -type ClientProxyConfig = { - path: string[]; - isBelievedBad?: boolean; -}; - -function makeSdkProxy(obj: T, { path, isBelievedBad = false }: ClientProxyConfig): T { - let proxy: T = objToProxy.get(obj); - - if (!proxy) { - proxy = new Proxy(obj, { - get(target, prop, receiver) { - const propPath = [...path, String(prop)]; - const value = Reflect.get(target, prop, receiver); - - if (isBelievedBad || (!(prop in target) && value === undefined)) { - // If we're accessing a path that doesn't exist, it will probably eventually error. - // Let's proxy it and mark it bad so that we can control the error message. - // We proxy an empty class so that an invocation or construction attempt is possible. - return makeSdkProxy(class {}, { path: propPath, isBelievedBad: true }); - } - - if (value !== null && (typeof value === 'object' || typeof value === 'function')) { - return makeSdkProxy(value, { path: propPath, isBelievedBad }); - } - - return value; - }, - - apply(target, thisArg, args) { - if (isBelievedBad || typeof target !== 'function') { - const fullyQualifiedMethodName = path.join('.'); - const suggestions = getMethodSuggestions(fullyQualifiedMethodName); - throw new Error( - `${fullyQualifiedMethodName} is not a function. Did you mean: ${suggestions.join(', ')}`, - ); - } - - return Reflect.apply(target, proxyToObj.get(thisArg) ?? thisArg, args); - }, - - construct(target, args, newTarget) { - if (isBelievedBad || typeof target !== 'function') { - const fullyQualifiedMethodName = path.join('.'); - const suggestions = getMethodSuggestions(fullyQualifiedMethodName); - throw new Error( - `${fullyQualifiedMethodName} is not a constructor. Did you mean: ${suggestions.join(', ')}`, - ); - } - - return Reflect.construct(target, args, newTarget); - }, - }); - - objToProxy.set(obj, proxy); - proxyToObj.set(proxy, obj); - } - - return proxy; -} - -function parseError(code: string, error: unknown): string | undefined { - if (!(error instanceof Error)) return; - const message = error.name ? `${error.name}: ${error.message}` : error.message; - try { - // Deno uses V8; the first ":LINE:COLUMN" is the top of stack. - const lineNumber = error.stack?.match(/:([0-9]+):[0-9]+/)?.[1]; - // -1 for the zero-based indexing - const line = - lineNumber && - code - .split('\n') - .at(parseInt(lineNumber, 10) - 1) - ?.trim(); - return line ? `${message}\n at line ${lineNumber}\n ${line}` : message; - } catch { - return message; - } -} - -const fetch = async (req: Request): Promise => { - const { opts, code } = (await req.json()) as WorkerInput; - if (code == null) { - return Response.json( - { - message: - 'The code param is missing. Provide one containing a top-level `run` function. Write code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```', - } satisfies WorkerError, - { status: 400, statusText: 'Code execution error' }, - ); - } - - const runFunctionNode = getRunFunctionNode(code); - if (!runFunctionNode) { - return Response.json( - { - message: - 'The code is missing a top-level `run` function. Write code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```', - } satisfies WorkerError, - { status: 400, statusText: 'Code execution error' }, - ); - } - - const client = new BeeperDesktop({ - ...opts, - }); - - const logLines: string[] = []; - const errLines: string[] = []; - const console = { - log: (...args: unknown[]) => { - logLines.push(util.format(...args)); - }, - error: (...args: unknown[]) => { - errLines.push(util.format(...args)); - }, - }; - try { - let run_ = async (client: any) => {}; - eval(`${code}\nrun_ = run;`); - const result = await run_(makeSdkProxy(client, { path: ['client'] })); - return Response.json({ - result, - logLines, - errLines, - } satisfies WorkerSuccess); - } catch (e) { - return Response.json( - { - message: parseError(code, e), - } satisfies WorkerError, - { status: 400, statusText: 'Code execution error' }, - ); - } -}; - -export default { fetch }; diff --git a/packages/mcp-server/src/code-tool.ts b/packages/mcp-server/src/code-tool.ts index fecf110..ed4b0c1 100644 --- a/packages/mcp-server/src/code-tool.ts +++ b/packages/mcp-server/src/code-tool.ts @@ -1,14 +1,9 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { dirname } from 'node:path'; -import { pathToFileURL } from 'node:url'; -import BeeperDesktop, { ClientOptions } from '@beeper/desktop-api'; -import { ContentBlock, Endpoint, Metadata, ToolCallResult } from './tools/types'; - +import { Metadata, ToolCallResult, asTextContentResult } from './tools/types'; import { Tool } from '@modelcontextprotocol/sdk/types.js'; - -import { WorkerInput, WorkerError, WorkerSuccess } from './code-tool-types'; - +import { readEnv } from './server'; +import { WorkerSuccess } from './code-tool-types'; /** * A tool that runs code against a copy of the SDK. * @@ -18,129 +13,45 @@ import { WorkerInput, WorkerError, WorkerSuccess } from './code-tool-types'; * * @param endpoints - The endpoints to include in the list. */ -export async function codeTool(): Promise { +export async function codeTool() { const metadata: Metadata = { resource: 'all', operation: 'write', tags: [] }; const tool: Tool = { name: 'execute', description: - 'Runs JavaScript code to interact with the API.\n\nYou are a skilled programmer writing code to interface with the service.\nDefine an async function named "run" that takes a single parameter of an initialized client named "client", and it will be run.\nWrite code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```\n\nYou will be returned anything that your function returns, plus the results of any console.log statements.\nIf any code triggers an error, the tool will return an error response, so you do not need to add error handling unless you want to output something more helpful than the raw error.\nIt is not necessary to add comments to code, unless by adding those comments you believe that you can generate better code.\nThis code will run in a container, and you will not be able to use fetch or otherwise interact with the network calls other than through the client you are given.\nAny variables you define won\'t live between successive uses of this call, so make sure to return or log any data you might need later.', + 'Runs JavaScript code to interact with the API.\n\nYou are a skilled programmer writing code to interface with the service.\nDefine an async function named "run" that takes a single parameter of an initialized SDK client and it will be run.\nWrite code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```\n\nYou will be returned anything that your function returns, plus the results of any console.log statements.\nIf any code triggers an error, the tool will return an error response, so you do not need to add error handling unless you want to output something more helpful than the raw error.\nIt is not necessary to add comments to code, unless by adding those comments you believe that you can generate better code.\nThis code will run in a container, and you will not be able to use fetch or otherwise interact with the network calls other than through the client you are given.\nAny variables you define won\'t live between successive uses of this call, so make sure to return or log any data you might need later.', inputSchema: { type: 'object', properties: { code: { type: 'string' } } }, }; - - // Import dynamically to avoid failing at import time in cases where the environment is not well-supported. - const { newDenoHTTPWorker } = await import('@valtown/deno-http-worker'); - const { workerPath } = await import('./code-tool-paths.cjs'); - - const handler = async (client: BeeperDesktop, args: unknown): Promise => { - const baseURLHostname = new URL(client.baseURL).hostname; - const { code } = args as { code: string }; - - const worker = await newDenoHTTPWorker(pathToFileURL(workerPath), { - runFlags: [ - `--node-modules-dir=manual`, - `--allow-read=code-tool-worker.mjs,${workerPath.replace(/([\/\\]node_modules)[\/\\].+$/, '$1')}/`, - `--allow-net=${baseURLHostname}`, - // Allow environment variables because instantiating the client will try to read from them, - // even though they are not set. - '--allow-env', - ], - printOutput: true, - spawnOptions: { - cwd: dirname(workerPath), + const handler = async (_: unknown, args: any): Promise => { + const code = args.code as string; + + // this is not required, but passing a Stainless API key for the matching project_name + // will allow you to run code-mode queries against non-published versions of your SDK. + const stainlessAPIKey = readEnv('STAINLESS_API_KEY'); + const codeModeEndpoint = + readEnv('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool'; + + const res = await fetch(codeModeEndpoint, { + method: 'POST', + headers: { + ...(stainlessAPIKey && { Authorization: stainlessAPIKey }), + 'Content-Type': 'application/json', + client_envs: JSON.stringify({ BEEPER_ACCESS_TOKEN: readEnv('BEEPER_ACCESS_TOKEN') }), }, + body: JSON.stringify({ + project_name: 'beeper-desktop-api', + code, + }), }); - try { - const resp = await new Promise((resolve, reject) => { - worker.addEventListener('exit', (exitCode) => { - reject(new Error(`Worker exited with code ${exitCode}`)); - }); - - const opts: ClientOptions = { - baseURL: client.baseURL, - accessToken: client.accessToken, - defaultHeaders: { - 'X-Stainless-MCP': 'true', - }, - }; - - const req = worker.request( - 'http://localhost', - { - headers: { - 'content-type': 'application/json', - }, - method: 'POST', - }, - (resp) => { - const body: Uint8Array[] = []; - resp.on('error', (err) => { - reject(err); - }); - resp.on('data', (chunk) => { - body.push(chunk); - }); - resp.on('end', () => { - resolve( - new Response(Buffer.concat(body).toString(), { - status: resp.statusCode ?? 200, - headers: resp.headers as any, - }), - ); - }); - }, - ); - - const body = JSON.stringify({ - opts, - code, - } satisfies WorkerInput); - - req.write(body, (err) => { - if (err != null) { - reject(err); - } - }); - - req.end(); - }); - - if (resp.status === 200) { - const { result, logLines, errLines } = (await resp.json()) as WorkerSuccess; - const returnOutput: ContentBlock | null = - result == null ? null : ( - { - type: 'text', - text: typeof result === 'string' ? result : JSON.stringify(result), - } - ); - const logOutput: ContentBlock | null = - logLines.length === 0 ? - null - : { - type: 'text', - text: logLines.join('\n'), - }; - const errOutput: ContentBlock | null = - errLines.length === 0 ? - null - : { - type: 'text', - text: 'Error output:\n' + errLines.join('\n'), - }; - return { - content: [returnOutput, logOutput, errOutput].filter((block) => block !== null), - }; - } else { - const { message } = (await resp.json()) as WorkerError; - return { - content: message == null ? [] : [{ type: 'text', text: message }], - isError: true, - }; - } - } finally { - worker.terminate(); + if (!res.ok) { + throw new Error( + `${res.status}: ${ + res.statusText + } error when trying to contact Code Tool server. Details: ${await res.text()}`, + ); } + + return asTextContentResult((await res.json()) as WorkerSuccess); }; return { metadata, tool, handler }; diff --git a/packages/mcp-server/src/docs-search-tool.ts b/packages/mcp-server/src/docs-search-tool.ts index eb89849..f80b5e4 100644 --- a/packages/mcp-server/src/docs-search-tool.ts +++ b/packages/mcp-server/src/docs-search-tool.ts @@ -13,8 +13,7 @@ export const metadata: Metadata = { export const tool: Tool = { name: 'search_docs', - description: - 'Search for documentation for how to use the client to interact with the API.\nThe tool will return an array of Markdown-formatted documentation pages.', + description: 'Search for documentation for how to use the client to interact with the API.', inputSchema: { type: 'object', properties: { @@ -25,7 +24,12 @@ export const tool: Tool = { language: { type: 'string', description: 'The language for the SDK to search for.', - enum: ['http', 'python', 'go', 'typescript', 'terraform', 'ruby', 'java', 'kotlin'], + enum: ['http', 'python', 'go', 'typescript', 'javascript', 'terraform', 'ruby', 'java', 'kotlin'], + }, + detail: { + type: 'string', + description: 'The amount of detail to return.', + enum: ['default', 'verbose'], }, }, required: ['query', 'language'], @@ -42,6 +46,13 @@ export const handler = async (_: unknown, args: Record | undefi const body = args as any; const query = new URLSearchParams(body).toString(); const result = await fetch(`${docsSearchURL}?${query}`); + + if (!result.ok) { + throw new Error( + `${result.status}: ${result.statusText} when using doc search tool. Details: ${await result.text()}`, + ); + } + return asTextContentResult(await result.json()); }; diff --git a/packages/mcp-server/src/filtering.ts b/packages/mcp-server/src/filtering.ts index 1aa9a40..eaae0fc 100644 --- a/packages/mcp-server/src/filtering.ts +++ b/packages/mcp-server/src/filtering.ts @@ -12,3 +12,7 @@ export async function maybeFilter(jqFilter: unknown | undefined, response: any): async function jq(json: any, jqFilter: string) { return (await initJq).json(json, jqFilter); } + +export function isJqError(error: any): error is Error { + return error instanceof Error && 'stderr' in error; +} diff --git a/packages/mcp-server/src/headers.ts b/packages/mcp-server/src/headers.ts index 5a76983..ee22980 100644 --- a/packages/mcp-server/src/headers.ts +++ b/packages/mcp-server/src/headers.ts @@ -11,7 +11,9 @@ export const parseAuthHeaders = (req: IncomingMessage): Partial = case 'Bearer': return { accessToken: req.headers.authorization.slice('Bearer '.length) }; default: - throw new Error(`Unsupported authorization scheme`); + throw new Error( + 'Unsupported authorization scheme. Expected the "Authorization" header to be a supported scheme (Bearer).', + ); } } diff --git a/packages/mcp-server/src/http.ts b/packages/mcp-server/src/http.ts index ae88c77..d078bf8 100644 --- a/packages/mcp-server/src/http.ts +++ b/packages/mcp-server/src/http.ts @@ -52,7 +52,7 @@ const newServer = ({ }, mcpOptions, }); - } catch { + } catch (error) { const resourceIdentifier = oauthResourceIdentifier(req); res.set( 'WWW-Authenticate', @@ -62,7 +62,7 @@ const newServer = ({ jsonrpc: '2.0', error: { code: -32000, - message: 'Unauthorized', + message: `Unauthorized: ${error instanceof Error ? error.message : error}`, }, }); return null; diff --git a/packages/mcp-server/src/server.ts b/packages/mcp-server/src/server.ts index a85a1b0..5c42bec 100644 --- a/packages/mcp-server/src/server.ts +++ b/packages/mcp-server/src/server.ts @@ -34,7 +34,7 @@ export const newMcpServer = () => new McpServer( { name: 'beeper_desktop_api_api', - version: '4.2.3', + version: '4.3.0', }, { capabilities: { tools: {}, logging: {} }, diff --git a/packages/mcp-server/src/tools/accounts/get-accounts.ts b/packages/mcp-server/src/tools/accounts/get-accounts.ts index 85fe44c..84f2cb6 100644 --- a/packages/mcp-server/src/tools/accounts/get-accounts.ts +++ b/packages/mcp-server/src/tools/accounts/get-accounts.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { Metadata, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; +import { Metadata, asErrorResult, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; import { Tool } from '@modelcontextprotocol/sdk/types.js'; import BeeperDesktop from '@beeper/desktop-api'; @@ -28,7 +28,14 @@ export const tool: Tool = { }; export const handler = async (client: BeeperDesktop, args: Record | undefined) => { - return asTextContentResult(await client.accounts.list()); + try { + return asTextContentResult(await client.accounts.list()); + } catch (error) { + if (error instanceof BeeperDesktop.APIError) { + return asErrorResult(error.message); + } + throw error; + } }; export default { metadata, tool, handler }; diff --git a/packages/mcp-server/src/tools/chats/get-chat.ts b/packages/mcp-server/src/tools/chats/get-chat.ts index 39c432a..d5b6e74 100644 --- a/packages/mcp-server/src/tools/chats/get-chat.ts +++ b/packages/mcp-server/src/tools/chats/get-chat.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { Metadata, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; +import { Metadata, asErrorResult, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; import { Tool } from '@modelcontextprotocol/sdk/types.js'; import BeeperDesktop from '@beeper/desktop-api'; @@ -39,7 +39,14 @@ export const tool: Tool = { export const handler = async (client: BeeperDesktop, args: Record | undefined) => { const { chatID, ...body } = args as any; - return asTextContentResult(await client.chats.retrieve(chatID, body)); + try { + return asTextContentResult(await client.chats.retrieve(chatID, body)); + } catch (error) { + if (error instanceof BeeperDesktop.APIError) { + return asErrorResult(error.message); + } + throw error; + } }; export default { metadata, tool, handler }; diff --git a/packages/mcp-server/src/tools/chats/search-chats.ts b/packages/mcp-server/src/tools/chats/search-chats.ts index f624726..7adeab5 100644 --- a/packages/mcp-server/src/tools/chats/search-chats.ts +++ b/packages/mcp-server/src/tools/chats/search-chats.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { Metadata, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; +import { Metadata, asErrorResult, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; import { Tool } from '@modelcontextprotocol/sdk/types.js'; import BeeperDesktop from '@beeper/desktop-api'; @@ -98,7 +98,14 @@ export const tool: Tool = { export const handler = async (client: BeeperDesktop, args: Record | undefined) => { const body = args as any; const response = await client.chats.search(body).asResponse(); - return asTextContentResult(await response.json()); + try { + return asTextContentResult(await response.json()); + } catch (error) { + if (error instanceof BeeperDesktop.APIError) { + return asErrorResult(error.message); + } + throw error; + } }; export default { metadata, tool, handler }; diff --git a/packages/mcp-server/src/tools/messages/list-messages.ts b/packages/mcp-server/src/tools/messages/list-messages.ts index 4b91ed5..f9840dc 100644 --- a/packages/mcp-server/src/tools/messages/list-messages.ts +++ b/packages/mcp-server/src/tools/messages/list-messages.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { Metadata, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; +import { Metadata, asErrorResult, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; import { Tool } from '@modelcontextprotocol/sdk/types.js'; import BeeperDesktop from '@beeper/desktop-api'; @@ -45,7 +45,14 @@ export const tool: Tool = { export const handler = async (client: BeeperDesktop, args: Record | undefined) => { const { chatID, ...body } = args as any; const response = await client.messages.list(chatID, body).asResponse(); - return asTextContentResult(await response.json()); + try { + return asTextContentResult(await response.json()); + } catch (error) { + if (error instanceof BeeperDesktop.APIError) { + return asErrorResult(error.message); + } + throw error; + } }; export default { metadata, tool, handler }; diff --git a/packages/mcp-server/src/tools/messages/search-messages.ts b/packages/mcp-server/src/tools/messages/search-messages.ts index b3392ba..89ae4d8 100644 --- a/packages/mcp-server/src/tools/messages/search-messages.ts +++ b/packages/mcp-server/src/tools/messages/search-messages.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { Metadata, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; +import { Metadata, asErrorResult, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; import { Tool } from '@modelcontextprotocol/sdk/types.js'; import BeeperDesktop from '@beeper/desktop-api'; @@ -117,7 +117,14 @@ export const tool: Tool = { export const handler = async (client: BeeperDesktop, args: Record | undefined) => { const body = args as any; const response = await client.messages.search(body).asResponse(); - return asTextContentResult(await response.json()); + try { + return asTextContentResult(await response.json()); + } catch (error) { + if (error instanceof BeeperDesktop.APIError) { + return asErrorResult(error.message); + } + throw error; + } }; export default { metadata, tool, handler }; diff --git a/packages/mcp-server/src/tools/messages/send-message.ts b/packages/mcp-server/src/tools/messages/send-message.ts index 9aff7a8..bf9b5ee 100644 --- a/packages/mcp-server/src/tools/messages/send-message.ts +++ b/packages/mcp-server/src/tools/messages/send-message.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { Metadata, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; +import { Metadata, asErrorResult, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; import { Tool } from '@modelcontextprotocol/sdk/types.js'; import BeeperDesktop from '@beeper/desktop-api'; @@ -41,7 +41,14 @@ export const tool: Tool = { export const handler = async (client: BeeperDesktop, args: Record | undefined) => { const { chatID, ...body } = args as any; - return asTextContentResult(await client.messages.send(chatID, body)); + try { + return asTextContentResult(await client.messages.send(chatID, body)); + } catch (error) { + if (error instanceof BeeperDesktop.APIError) { + return asErrorResult(error.message); + } + throw error; + } }; export default { metadata, tool, handler }; diff --git a/packages/mcp-server/src/tools/top-level/focus-app.ts b/packages/mcp-server/src/tools/top-level/focus-app.ts index e308e6b..f1c5e76 100644 --- a/packages/mcp-server/src/tools/top-level/focus-app.ts +++ b/packages/mcp-server/src/tools/top-level/focus-app.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { Metadata, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; +import { Metadata, asErrorResult, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; import { Tool } from '@modelcontextprotocol/sdk/types.js'; import BeeperDesktop from '@beeper/desktop-api'; @@ -46,7 +46,14 @@ export const tool: Tool = { export const handler = async (client: BeeperDesktop, args: Record | undefined) => { const body = args as any; - return asTextContentResult(await client.focus(body)); + try { + return asTextContentResult(await client.focus(body)); + } catch (error) { + if (error instanceof BeeperDesktop.APIError) { + return asErrorResult(error.message); + } + throw error; + } }; export default { metadata, tool, handler }; diff --git a/packages/mcp-server/src/tools/top-level/search.ts b/packages/mcp-server/src/tools/top-level/search.ts index ce1bdfb..52c575e 100644 --- a/packages/mcp-server/src/tools/top-level/search.ts +++ b/packages/mcp-server/src/tools/top-level/search.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { Metadata, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; +import { Metadata, asErrorResult, asTextContentResult } from '@beeper/desktop-mcp/tools/types'; import { Tool } from '@modelcontextprotocol/sdk/types.js'; import BeeperDesktop from '@beeper/desktop-api'; @@ -35,7 +35,14 @@ export const tool: Tool = { export const handler = async (client: BeeperDesktop, args: Record | undefined) => { const body = args as any; - return asTextContentResult(await client.search(body)); + try { + return asTextContentResult(await client.search(body)); + } catch (error) { + if (error instanceof BeeperDesktop.APIError) { + return asErrorResult(error.message); + } + throw error; + } }; export default { metadata, tool, handler }; diff --git a/packages/mcp-server/src/tools/types.ts b/packages/mcp-server/src/tools/types.ts index d484ddf..120ee5b 100644 --- a/packages/mcp-server/src/tools/types.ts +++ b/packages/mcp-server/src/tools/types.ts @@ -87,6 +87,18 @@ export async function asBinaryContentResult(response: Response): Promise