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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.1.0"
".": "1.1.1"
}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 1.1.1 (2026-04-03)

Full Changelog: [v1.1.0...v1.1.1](https://github.com/context-dot-dev/context-typescript-sdk/compare/v1.1.0...v1.1.1)

### Chores

* **internal:** fix MCP docker image builds in yarn projects ([d7023c7](https://github.com/context-dot-dev/context-typescript-sdk/commit/d7023c786b668d3afc62d151698bd05d0ab35f56))
* **internal:** improve local docs search for MCP servers ([2a5884c](https://github.com/context-dot-dev/context-typescript-sdk/commit/2a5884cf913182d4cb05e5cc3a9a86f9a74aea47))
* **internal:** improve local docs search for MCP servers ([6c0fe3f](https://github.com/context-dot-dev/context-typescript-sdk/commit/6c0fe3fb873609517518ce1b0b5d5a9c1a788d62))
* **internal:** support type annotations when running MCP in local execution mode ([1b6f120](https://github.com/context-dot-dev/context-typescript-sdk/commit/1b6f1206b80413ac77ab7be9b471525323cb3efc))
* **internal:** use link instead of file in MCP server package.json files ([dbabdac](https://github.com/context-dot-dev/context-typescript-sdk/commit/dbabdac818620983c0d464313aea3f8efa854772))
* **mcp-server:** add support for session id, forward client info ([bb8cffe](https://github.com/context-dot-dev/context-typescript-sdk/commit/bb8cffe6ec501635c5c90206e2578f626ae11949))
* **mcp-server:** log client info ([ae415f7](https://github.com/context-dot-dev/context-typescript-sdk/commit/ae415f745c8e24bc82b42ade8be3b5d43925422f))

## 1.1.0 (2026-03-28)

Full Changelog: [v1.0.1...v1.1.0](https://github.com/context-dot-dev/context-typescript-sdk/compare/v1.0.1...v1.1.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": "context.dev",
"version": "1.1.0",
"version": "1.1.1",
"description": "The official TypeScript library for the Context Dev API",
"author": "Context Dev <hello@context.dev>",
"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/context.dev

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": "context.dev-mcp",
"version": "1.1.0",
"version": "1.1.1",
"description": "The official MCP Server for the Context Dev API",
"author": {
"name": "Context Dev",
Expand Down
4 changes: 2 additions & 2 deletions packages/mcp-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "context.dev-mcp",
"version": "1.1.0",
"version": "1.1.1",
"description": "The official MCP Server for the Context Dev API",
"author": "Context Dev <hello@context.dev>",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -30,7 +30,7 @@
"fix": "eslint --fix ."
},
"dependencies": {
"context.dev": "file:../../dist/",
"context.dev": "link:../../dist/",
"ajv": "^8.18.0",
"@cloudflare/cabidela": "^0.2.4",
"@hono/node-server": "^1.19.10",
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 { ContextDev, ClientOptions } from 'context.dev';

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 @@ -256,7 +260,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 @@ -266,7 +272,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 @@ -284,6 +290,8 @@ const fetch = async (req: Request): Promise<Response> => {
} satisfies WorkerOutput,
{ status: 400, statusText: 'Code execution error' },
);
} finally {
globalThis.console = originalConsole;
}
};

Expand Down
28 changes: 10 additions & 18 deletions packages/mcp-server/src/docs-search-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,35 @@ export function setLocalSearch(search: LocalDocsSearch): void {
_localSearch = search;
}

const SUPPORTED_LANGUAGES = new Set(['http', 'typescript', 'javascript']);

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) ?? 'verbose';

if (!SUPPORTED_LANGUAGES.has(language)) {
throw new Error(
`Local docs search only supports HTTP, TypeScript, and JavaScript. Got language="${language}". ` +
`Use --docs-search-mode stainless-api for other languages, or set language to "http", "typescript", or "javascript".`,
);
}
const detail = (args['detail'] as string) ?? 'default';

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

async function searchRemote(
args: Record<string, unknown>,
stainlessApiKey: string | undefined,
): Promise<unknown> {
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: {
...(stainlessApiKey && { Authorization: stainlessApiKey }),
...(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 All @@ -105,7 +97,7 @@ async function searchRemote(
'Got error response from docs search tool',
);

if (result.status === 404 && !stainlessApiKey) {
if (result.status === 404 && !reqContext.stainlessApiKey) {
throw new Error(
'Could not find docs for this project. You may need to provide a Stainless API key via the STAINLESS_API_KEY environment variable, the --stainless-api-key flag, or the x-stainless-api-key HTTP header.',
);
Expand Down Expand Up @@ -140,7 +132,7 @@ export const handler = async ({
return asTextContentResult(await searchLocal(body));
}

return asTextContentResult(await searchRemote(body, reqContext.stainlessApiKey));
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