Skip to content
Merged
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.CONTEXT_DEV_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 @@
{
".": "1.0.1"
".": "1.1.0"
}
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 20
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-ea89aeedfdd75f71542bcbb53880ecbc07f2656945d9ac8dce55d7bdabc5f8cc.yml
openapi_spec_hash: c4dd62c3a3dc8c59a050fb6a76ab5f1b
config_hash: df40ba3de7dbee2faf0315c5fbd001dc
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-2ddb6d73ec8831eee4cb4352b85843a1f6f444e48d8be837cfcd118eddd2a63e.yml
openapi_spec_hash: 1163122fba27e56fa5879bc98d32ee14
config_hash: 38268bb88fc4dcbb8f2f94dd138b5910
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## 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)

### Features

* **api:** api update ([a2de140](https://github.com/context-dot-dev/context-typescript-sdk/commit/a2de140e3c6fc84fc1ac6ba0687791ebd240442a))
* **api:** api update ([5a78e41](https://github.com/context-dot-dev/context-typescript-sdk/commit/5a78e4152accbe64cb41dbc43f057132fd651b44))


### Chores

* **ci:** escape input path in publish-npm workflow ([bb90d39](https://github.com/context-dot-dev/context-typescript-sdk/commit/bb90d39c47c8eb13a337507ffc03ccef93db197b))
* **internal:** codegen related update ([c658fd1](https://github.com/context-dot-dev/context-typescript-sdk/commit/c658fd1b8f7270e2d54c9aed39b59b67b165c496))
* **internal:** support custom-instructions-path flag in MCP servers ([34b0150](https://github.com/context-dot-dev/context-typescript-sdk/commit/34b0150e4887578596139019d36b045a6b09cc88))
* **internal:** support local docs search in MCP servers ([118d95d](https://github.com/context-dot-dev/context-typescript-sdk/commit/118d95dc88b884f3210f5be2c36335eb2f728a49))

## 1.0.1 (2026-03-25)

Full Changelog: [v1.0.0...v1.0.1](https://github.com/context-dot-dev/context-typescript-sdk/compare/v1.0.0...v1.0.1)
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.0.1",
"version": "1.1.0",
"description": "The official TypeScript library for the Context Dev API",
"author": "Context Dev <hello@context.dev>",
"types": "dist/index.d.ts",
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.0.1",
"version": "1.1.0",
"description": "The official MCP Server for the Context Dev API",
"author": {
"name": "Context Dev",
Expand Down
3 changes: 2 additions & 1 deletion 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.0.1",
"version": "1.1.0",
"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 @@ -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
66 changes: 56 additions & 10 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,49 @@ export const tool: Tool = {
const docsSearchURL =
process.env['DOCS_SEARCH_URL'] || 'https://api.stainless.com/api/projects/context.dev/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;
}

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".`,
);
}

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

async function searchRemote(
args: Record<string, unknown>,
stainlessApiKey: string | undefined,
): 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 }),
...(stainlessApiKey && { Authorization: stainlessApiKey }),
},
});

Expand All @@ -75,7 +105,7 @@ export const handler = async ({
'Got error response from docs search tool',
);

if (result.status === 404 && !reqContext.stainlessApiKey) {
if (result.status === 404 && !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 All @@ -94,7 +124,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.stainlessApiKey));
};

export default { metadata, tool, handler };
3 changes: 2 additions & 1 deletion packages/mcp-server/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const newServer = async ({
res: express.Response;
}): Promise<McpServer | null> => {
const stainlessApiKey = getStainlessApiKey(req, mcpOptions);
const server = await newMcpServer(stainlessApiKey);
const customInstructionsPath = mcpOptions.customInstructionsPath;
const server = await newMcpServer({ stainlessApiKey, customInstructionsPath });

const authOptions = parseClientAuthHeaders(req, false);

Expand Down
31 changes: 27 additions & 4 deletions packages/mcp-server/src/instructions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import fs from 'fs/promises';
import { readEnv } from './util';
import { getLogger } from './logger';

Expand All @@ -12,9 +13,15 @@ interface InstructionsCacheEntry {

const instructionsCache = new Map<string, InstructionsCacheEntry>();

export async function getInstructions(stainlessApiKey: string | undefined): Promise<string> {
export async function getInstructions({
stainlessApiKey,
customInstructionsPath,
}: {
stainlessApiKey?: string | undefined;
customInstructionsPath?: string | undefined;
}): Promise<string> {
const now = Date.now();
const cacheKey = stainlessApiKey ?? '';
const cacheKey = customInstructionsPath ?? stainlessApiKey ?? '';
const cached = instructionsCache.get(cacheKey);

if (cached && now - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
Expand All @@ -28,12 +35,28 @@ export async function getInstructions(stainlessApiKey: string | undefined): Prom
}
}

const fetchedInstructions = await fetchLatestInstructions(stainlessApiKey);
let fetchedInstructions: string;

if (customInstructionsPath) {
fetchedInstructions = await fetchLatestInstructionsFromFile(customInstructionsPath);
} else {
fetchedInstructions = await fetchLatestInstructionsFromApi(stainlessApiKey);
}

instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: now });
return fetchedInstructions;
}

async function fetchLatestInstructions(stainlessApiKey: string | undefined): Promise<string> {
async function fetchLatestInstructionsFromFile(path: string): Promise<string> {
try {
return await fs.readFile(path, 'utf-8');
} catch (error) {
getLogger().error({ error, path }, 'Error fetching instructions from file');
throw error;
}
}

async function fetchLatestInstructionsFromApi(stainlessApiKey: string | undefined): Promise<string> {
// Setting the stainless API key is optional, but may be required
// to authenticate requests to the Stainless API.
const response = await fetch(
Expand Down
Loading
Loading