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
5 changes: 3 additions & 2 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ jobs:

- name: Publish to NPM
run: |
if [ -n "${{ github.event.inputs.path }}" ]; then
PATHS_RELEASED='[\"${{ github.event.inputs.path }}\"]'
if [ -n "$INPUT_PATH" ]; then
PATHS_RELEASED="[\"$INPUT_PATH\"]"
else
PATHS_RELEASED='[\".\", \"packages/mcp-server\"]'
fi
yarn tsn scripts/publish-packages.ts "{ \"paths_released\": \"$PATHS_RELEASED\" }"
env:
INPUT_PATH: ${{ github.event.inputs.path }}
NPM_TOKEN: ${{ secrets.FINCH_NPM_TOKEN || secrets.NPM_TOKEN }}

- name: Upload MCP Server DXT GitHub release asset
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "9.4.0"
".": "9.4.1"
}
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 9.4.1 (2026-04-02)

Full Changelog: [v9.4.0...v9.4.1](https://github.com/Finch-API/finch-api-node/compare/v9.4.0...v9.4.1)

### Chores

* **ci:** escape input path in publish-npm workflow ([937becb](https://github.com/Finch-API/finch-api-node/commit/937becb997cb913a0328004f30e659267b4e6408))
* **internal:** fix MCP docker image builds in yarn projects ([82c9ea5](https://github.com/Finch-API/finch-api-node/commit/82c9ea5c80252c99b5a6f5454341e77c36b5bf27))
* **internal:** improve local docs search for MCP servers ([996bc5f](https://github.com/Finch-API/finch-api-node/commit/996bc5f36e0c86bdc9af549e70f3f4edaebb5d3c))
* **internal:** improve local docs search for MCP servers ([718d076](https://github.com/Finch-API/finch-api-node/commit/718d076ca4e7646b354ddb90bd481d870afcfff0))
* **internal:** support local docs search in MCP servers ([c1b4351](https://github.com/Finch-API/finch-api-node/commit/c1b4351dfc3afdf78cb3b05303da95b38f7f063d))
* **internal:** support type annotations when running MCP in local execution mode ([dee433e](https://github.com/Finch-API/finch-api-node/commit/dee433e64a5b46bb3cdfcdae22f0e7e3bf0cf624))
* **internal:** use link instead of file in MCP server package.json files ([93c6720](https://github.com/Finch-API/finch-api-node/commit/93c6720c745b801c0740737164bd316f185d20df))
* **mcp-server:** add support for session id, forward client info ([c4e007e](https://github.com/Finch-API/finch-api-node/commit/c4e007e78562fdab27d1dfba7be94cf1b03a57a4))
* **mcp-server:** log client info ([9a5e04e](https://github.com/Finch-API/finch-api-node/commit/9a5e04ebe0ab27ee31ddf23fcca0cd7256b729ca))
* **tests:** bump steady to v0.20.1 ([d50d641](https://github.com/Finch-API/finch-api-node/commit/d50d641be70b27821146bad6c1d708919954765c))
* **tests:** bump steady to v0.20.2 ([034ea66](https://github.com/Finch-API/finch-api-node/commit/034ea662efe9f95db50f2dca215f54e63ff96009))

## 9.4.0 (2026-03-27)

Full Changelog: [v9.3.0...v9.4.0](https://github.com/Finch-API/finch-api-node/compare/v9.3.0...v9.4.0)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tryfinch/finch-api",
"version": "9.4.0",
"version": "9.4.1",
"description": "The official TypeScript library for the Finch API",
"author": "Finch <founders@tryfinch.com>",
"types": "dist/index.d.ts",
Expand Down
4 changes: 3 additions & 1 deletion packages/mcp-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ COPY . .

# Install all dependencies and build everything
RUN yarn install --frozen-lockfile && \
yarn build
yarn build && \
# Remove the symlink to the SDK so it doesn't interfere with the explicit COPY below
rm -Rf packages/mcp-server/node_modules/@tryfinch/finch-api

FROM denoland/deno:alpine-2.7.1

Expand Down
2 changes: 1 addition & 1 deletion packages/mcp-server/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dxt_version": "0.2",
"name": "@tryfinch/finch-api-mcp",
"version": "9.4.0",
"version": "9.4.1",
"description": "The official MCP Server for the Finch API",
"author": {
"name": "Finch",
Expand Down
5 changes: 3 additions & 2 deletions packages/mcp-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tryfinch/finch-api-mcp",
"version": "9.4.0",
"version": "9.4.1",
"description": "The official MCP Server for the Finch API",
"author": "Finch <founders@tryfinch.com>",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -30,7 +30,7 @@
"fix": "eslint --fix ."
},
"dependencies": {
"@tryfinch/finch-api": "file:../../dist/",
"@tryfinch/finch-api": "link:../../dist/",
"ajv": "^8.18.0",
"@cloudflare/cabidela": "^0.2.4",
"@hono/node-server": "^1.19.10",
Expand All @@ -41,6 +41,7 @@
"cors": "^2.8.5",
"express": "^5.1.0",
"fuse.js": "^7.1.0",
"minisearch": "^7.2.0",
"jq-web": "https://github.com/stainless-api/jq-web/releases/download/v0.8.8/jq-web.tar.gz",
"pino": "^10.3.1",
"pino-http": "^11.0.0",
Expand Down
12 changes: 10 additions & 2 deletions packages/mcp-server/src/code-tool-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import ts from 'typescript';
import { WorkerOutput } from './code-tool-types';
import { Finch, ClientOptions } from '@tryfinch/finch-api';

async function tseval(code: string) {
return import('data:application/typescript;charset=utf-8;base64,' + Buffer.from(code).toString('base64'));
}

function getRunFunctionSource(code: string): {
type: 'declaration' | 'expression';
client: string | undefined;
Expand Down Expand Up @@ -283,7 +287,9 @@ const fetch = async (req: Request): Promise<Response> => {

const log_lines: string[] = [];
const err_lines: string[] = [];
const console = {
const originalConsole = globalThis.console;
globalThis.console = {
...originalConsole,
log: (...args: unknown[]) => {
log_lines.push(util.format(...args));
},
Expand All @@ -293,7 +299,7 @@ const fetch = async (req: Request): Promise<Response> => {
};
try {
let run_ = async (client: any) => {};
eval(`${code}\nrun_ = run;`);
run_ = (await tseval(`${code}\nexport default run;`)).default;
const result = await run_(makeSdkProxy(client, { path: ['client'] }));
return Response.json({
is_error: false,
Expand All @@ -311,6 +317,8 @@ const fetch = async (req: Request): Promise<Response> => {
} satisfies WorkerOutput,
{ status: 400, statusText: 'Code execution error' },
);
} finally {
globalThis.console = originalConsole;
}
};

Expand Down
54 changes: 46 additions & 8 deletions packages/mcp-server/src/docs-search-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Tool } from '@modelcontextprotocol/sdk/types.js';
import { Metadata, McpRequestContext, asTextContentResult } from './types';
import { getLogger } from './logger';
import type { LocalDocsSearch } from './local-docs-search';

export const metadata: Metadata = {
resource: 'all',
Expand Down Expand Up @@ -43,20 +44,41 @@ export const tool: Tool = {
const docsSearchURL =
process.env['DOCS_SEARCH_URL'] || 'https://api.stainless.com/api/projects/finch/docs/search';

export const handler = async ({
reqContext,
args,
}: {
reqContext: McpRequestContext;
args: Record<string, unknown> | undefined;
}) => {
let _localSearch: LocalDocsSearch | undefined;

export function setLocalSearch(search: LocalDocsSearch): void {
_localSearch = search;
}

async function searchLocal(args: Record<string, unknown>): Promise<unknown> {
if (!_localSearch) {
throw new Error('Local search not initialized');
}

const query = (args['query'] as string) ?? '';
const language = (args['language'] as string) ?? 'typescript';
const detail = (args['detail'] as string) ?? 'default';

return _localSearch.search({
query,
language,
detail,
maxResults: 5,
}).results;
}

async function searchRemote(args: Record<string, unknown>, reqContext: McpRequestContext): Promise<unknown> {
const body = args as any;
const query = new URLSearchParams(body).toString();

const startTime = Date.now();
const result = await fetch(`${docsSearchURL}?${query}`, {
headers: {
...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }),
...(reqContext.mcpSessionId && { 'x-stainless-mcp-session-id': reqContext.mcpSessionId }),
...(reqContext.mcpClientInfo && {
'x-stainless-mcp-client-info': JSON.stringify(reqContext.mcpClientInfo),
}),
},
});

Expand Down Expand Up @@ -94,7 +116,23 @@ export const handler = async ({
},
'Got docs search result',
);
return asTextContentResult(resultBody);
return resultBody;
}

export const handler = async ({
reqContext,
args,
}: {
reqContext: McpRequestContext;
args: Record<string, unknown> | undefined;
}) => {
const body = args ?? {};

if (_localSearch) {
return asTextContentResult(await searchLocal(body));
}

return asTextContentResult(await searchRemote(body, reqContext));
};

export default { metadata, tool, handler };
25 changes: 25 additions & 0 deletions packages/mcp-server/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ const newServer = async ({
}
}

const mcpClientInfo =
typeof req.body?.params?.clientInfo?.name === 'string' ?
{ name: req.body.params.clientInfo.name, version: String(req.body.params.clientInfo.version ?? '') }
: undefined;

await initMcpServer({
server: server,
mcpOptions: effectiveMcpOptions,
Expand All @@ -78,8 +83,14 @@ const newServer = async ({
},
stainlessApiKey: stainlessApiKey,
upstreamClientEnvs,
mcpSessionId: (req as any).mcpSessionId,
mcpClientInfo,
});

if (mcpClientInfo) {
getLogger().info({ mcpSessionId: (req as any).mcpSessionId, mcpClientInfo }, 'MCP client connected');
}

return server;
};

Expand Down Expand Up @@ -135,9 +146,23 @@ export const streamableHTTPApp = ({
const app = express();
app.set('query parser', 'extended');
app.use(express.json());
app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
const existing = req.headers['mcp-session-id'];
const sessionId = (Array.isArray(existing) ? existing[0] : existing) || crypto.randomUUID();
(req as any).mcpSessionId = sessionId;
const origWriteHead = res.writeHead.bind(res);
res.writeHead = function (statusCode: number, ...rest: any[]) {
res.setHeader('mcp-session-id', sessionId);
return origWriteHead(statusCode, ...rest);
} as typeof res.writeHead;
next();
});
app.use(
pinoHttp({
logger: getLogger(),
customProps: (req) => ({
mcpSessionId: (req as any).mcpSessionId,
}),
customLogLevel: (req, res) => {
if (res.statusCode >= 500) {
return 'error';
Expand Down
Loading
Loading