@sourcebot/mcp 1.0.16 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +1 -0
- package/dist/client.d.ts +14 -11
- package/dist/env.d.ts +1 -1
- package/dist/env.js +2 -2
- package/dist/env.js.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/schemas.d.ts +79 -980
- package/dist/schemas.js +7 -0
- package/dist/schemas.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.0.18] - 2026-02-28
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- Bumped `@modelcontextprotocol/sdk` from 1.10.2 to 1.26.0. [#958](https://github.com/sourcebot-dev/sourcebot/pull/958)
|
|
14
|
+
- Bumped `zod` from `^3.24.3` to `^4.3.6`. [#964](https://github.com/sourcebot-dev/sourcebot/pull/964)
|
|
15
|
+
|
|
16
|
+
## [1.0.17] - 2026-02-19
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- Added optional `visibility` parameter to `ask_codebase` tool to allow controlling chat session visibility in shared environments. [#903](https://github.com/sourcebot-dev/sourcebot/pull/903)
|
|
20
|
+
- Added `defaultBranch`, `isFork`, and `isArchived` fields to the `list_repos` tool response. [#905](https://github.com/sourcebot-dev/sourcebot/pull/905)
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- Changed `SOURCEBOT_HOST` to default to `http://localhost:3000` instead of `https://demo.sourcebot.dev`, which is now deprecated. [#906](https://github.com/sourcebot-dev/sourcebot/pull/906)
|
|
24
|
+
|
|
10
25
|
## [1.0.16] - 2026-02-10
|
|
11
26
|
|
|
12
27
|
### Added
|
package/README.md
CHANGED
|
@@ -276,6 +276,7 @@ Ask a natural language question about the codebase. This tool uses an AI agent t
|
|
|
276
276
|
| `query` | yes | The query to ask about the codebase. |
|
|
277
277
|
| `repos` | no | The repositories that are accessible to the agent during the chat. If not provided, all repositories are accessible. |
|
|
278
278
|
| `languageModel` | no | The language model to use for answering the question. Object with `provider` and `model`. If not provided, defaults to the first model in the config. Use `list_language_models` to see available options. |
|
|
279
|
+
| `visibility` | no | The visibility of the chat session (`'PRIVATE'` or `'PUBLIC'`). Defaults to `PRIVATE` for authenticated users and `PUBLIC` for anonymous users. Set to `PUBLIC` to make the chat viewable by anyone with the link (useful in shared environments like Slack). |
|
|
279
280
|
|
|
280
281
|
</details>
|
|
281
282
|
|
package/dist/client.d.ts
CHANGED
|
@@ -24,7 +24,6 @@ export declare const search: (request: SearchRequest) => Promise<{
|
|
|
24
24
|
flushReason: string;
|
|
25
25
|
};
|
|
26
26
|
files: {
|
|
27
|
-
webUrl: string;
|
|
28
27
|
fileName: {
|
|
29
28
|
text: string;
|
|
30
29
|
matchRanges: {
|
|
@@ -40,10 +39,12 @@ export declare const search: (request: SearchRequest) => Promise<{
|
|
|
40
39
|
};
|
|
41
40
|
}[];
|
|
42
41
|
};
|
|
42
|
+
webUrl: string;
|
|
43
43
|
repository: string;
|
|
44
44
|
repositoryId: number;
|
|
45
45
|
language: string;
|
|
46
46
|
chunks: {
|
|
47
|
+
content: string;
|
|
47
48
|
matchRanges: {
|
|
48
49
|
start: {
|
|
49
50
|
byteOffset: number;
|
|
@@ -56,7 +57,6 @@ export declare const search: (request: SearchRequest) => Promise<{
|
|
|
56
57
|
column: number;
|
|
57
58
|
};
|
|
58
59
|
}[];
|
|
59
|
-
content: string;
|
|
60
60
|
contentStart: {
|
|
61
61
|
byteOffset: number;
|
|
62
62
|
lineNumber: number;
|
|
@@ -72,8 +72,8 @@ export declare const search: (request: SearchRequest) => Promise<{
|
|
|
72
72
|
}[] | undefined;
|
|
73
73
|
}[];
|
|
74
74
|
externalWebUrl?: string | undefined;
|
|
75
|
-
content?: string | undefined;
|
|
76
75
|
branches?: string[] | undefined;
|
|
76
|
+
content?: string | undefined;
|
|
77
77
|
}[];
|
|
78
78
|
repositoryInfo: {
|
|
79
79
|
id: number;
|
|
@@ -87,33 +87,36 @@ export declare const search: (request: SearchRequest) => Promise<{
|
|
|
87
87
|
export declare const listRepos: (queryParams?: ListReposQueryParams) => Promise<{
|
|
88
88
|
repos: {
|
|
89
89
|
codeHostType: string;
|
|
90
|
-
webUrl: string;
|
|
91
90
|
repoId: number;
|
|
92
91
|
repoName: string;
|
|
93
|
-
|
|
92
|
+
webUrl: string;
|
|
93
|
+
isFork: boolean;
|
|
94
|
+
isArchived: boolean;
|
|
94
95
|
repoDisplayName?: string | undefined;
|
|
96
|
+
externalWebUrl?: string | undefined;
|
|
95
97
|
imageUrl?: string | undefined;
|
|
96
98
|
indexedAt?: Date | undefined;
|
|
97
99
|
pushedAt?: Date | undefined;
|
|
100
|
+
defaultBranch?: string | undefined;
|
|
98
101
|
}[];
|
|
99
102
|
totalCount: number;
|
|
100
103
|
}>;
|
|
101
104
|
export declare const getFileSource: (request: FileSourceRequest) => Promise<{
|
|
102
|
-
|
|
103
|
-
webUrl: string;
|
|
105
|
+
source: string;
|
|
104
106
|
language: string;
|
|
107
|
+
path: string;
|
|
105
108
|
repo: string;
|
|
106
|
-
source: string;
|
|
107
109
|
repoCodeHostType: string;
|
|
108
|
-
|
|
110
|
+
webUrl: string;
|
|
109
111
|
repoDisplayName?: string | undefined;
|
|
110
112
|
repoExternalWebUrl?: string | undefined;
|
|
113
|
+
externalWebUrl?: string | undefined;
|
|
111
114
|
}>;
|
|
112
115
|
export declare const listCommits: (queryParams: ListCommitsQueryParamsSchema) => Promise<{
|
|
113
116
|
commits: {
|
|
114
|
-
message: string;
|
|
115
|
-
date: string;
|
|
116
117
|
hash: string;
|
|
118
|
+
date: string;
|
|
119
|
+
message: string;
|
|
117
120
|
refs: string;
|
|
118
121
|
body: string;
|
|
119
122
|
author_name: string;
|
package/dist/env.d.ts
CHANGED
package/dist/env.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createEnv } from "@t3-oss/env-core";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
export const numberSchema = z.coerce.number();
|
|
4
|
-
const
|
|
4
|
+
const SOURCEBOT_DEFAULT_HOST = "http://localhost:3000";
|
|
5
5
|
export const env = createEnv({
|
|
6
6
|
server: {
|
|
7
|
-
SOURCEBOT_HOST: z.string().url().default(
|
|
7
|
+
SOURCEBOT_HOST: z.string().url().default(SOURCEBOT_DEFAULT_HOST),
|
|
8
8
|
SOURCEBOT_API_KEY: z.string().optional(),
|
|
9
9
|
// The minimum number of tokens to return
|
|
10
10
|
DEFAULT_MINIMUM_TOKENS: numberSchema.default(10000),
|
package/dist/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;AAE9C,MAAM,
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;AAE9C,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AAEvD,MAAM,CAAC,MAAM,GAAG,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE;QACJ,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,sBAAsB,CAAC;QAEhE,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAExC,yCAAyC;QACzC,sBAAsB,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC;QAEnD,sDAAsD;QACtD,eAAe,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC;QAE5C,yDAAyD;QACzD,qBAAqB,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;KACjD;IACD,UAAU,EAAE,OAAO,CAAC,GAAG;IACvB,sBAAsB,EAAE,IAAI;CAC/B,CAAC,CAAC","sourcesContent":["import { createEnv } from \"@t3-oss/env-core\";\nimport { z } from \"zod\";\n\nexport const numberSchema = z.coerce.number();\n\nconst SOURCEBOT_DEFAULT_HOST = \"http://localhost:3000\";\n\nexport const env = createEnv({\n server: {\n SOURCEBOT_HOST: z.string().url().default(SOURCEBOT_DEFAULT_HOST),\n\n SOURCEBOT_API_KEY: z.string().optional(),\n\n // The minimum number of tokens to return\n DEFAULT_MINIMUM_TOKENS: numberSchema.default(10000),\n\n // The number of matches to fetch from the search API.\n DEFAULT_MATCHES: numberSchema.default(10000),\n\n // The number of lines to include above and below a match\n DEFAULT_CONTEXT_LINES: numberSchema.default(5),\n },\n runtimeEnv: process.env,\n emptyStringAsUndefined: true,\n});"]}
|
package/dist/index.js
CHANGED
|
@@ -156,6 +156,9 @@ server.tool("list_repos", dedent `Lists repositories in the organization with op
|
|
|
156
156
|
name: repo.repoName,
|
|
157
157
|
url: repo.webUrl,
|
|
158
158
|
pushedAt: repo.pushedAt,
|
|
159
|
+
defaultBranch: repo.defaultBranch,
|
|
160
|
+
isFork: repo.isFork,
|
|
161
|
+
isArchived: repo.isArchived,
|
|
159
162
|
})),
|
|
160
163
|
totalCount: result.totalCount,
|
|
161
164
|
})
|
|
@@ -311,6 +314,8 @@ server.tool("ask_codebase", dedent `
|
|
|
311
314
|
|
|
312
315
|
Returns a detailed answer in markdown format with code references, plus a link to view the full research session (including all tool calls and reasoning) in the Sourcebot web UI.
|
|
313
316
|
|
|
317
|
+
When using this in shared environments (e.g., Slack), you can set the visibility parameter to 'PUBLIC' to ensure everyone can access the chat link.
|
|
318
|
+
|
|
314
319
|
This is a blocking operation that may take 30-60+ seconds for complex questions as the agent researches the codebase.
|
|
315
320
|
`, askCodebaseRequestSchema.shape, async (request) => {
|
|
316
321
|
const response = await askCodebase(request);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,iCAAiC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,OAAO,MAAM,QAAQ,CAAC;AAC7B,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,kBAAkB,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACvH,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEtP,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElG,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;AAE1D,oBAAoB;AACpB,MAAM,MAAM,GAAG,IAAI,SAAS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AAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AACpC,CAAC,CAAA;AAED,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACxB,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;IACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\n// Entry point for the MCP server\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport _dedent from \"dedent\";\nimport escapeStringRegexp from 'escape-string-regexp';\nimport { z } from 'zod';\nimport { askCodebase, getFileSource, listCommits, listLanguageModels, listRepos, listTree, search } from './client.js';\nimport { env, numberSchema } from './env.js';\nimport { askCodebaseRequestSchema, DEFAULT_MAX_TREE_ENTRIES, DEFAULT_TREE_DEPTH, fileSourceRequestSchema, listCommitsQueryParamsSchema, listReposQueryParamsSchema, listTreeRequestSchema, MAX_MAX_TREE_ENTRIES, MAX_TREE_DEPTH } from './schemas.js';\nimport { AskCodebaseRequest, FileSourceRequest, ListCommitsQueryParamsSchema, ListReposQueryParams, ListTreeEntry, ListTreeRequest, TextContent } from './types.js';\nimport { buildTreeNodeIndex, joinTreePath, normalizeTreePath, sortTreeEntries } from './utils.js';\n\nconst dedent = _dedent.withOptions({ alignValues: true });\n\n// Create MCP server\nconst server = new McpServer({\n name: 'sourcebot-mcp-server',\n version: '0.1.0',\n});\n\n\nserver.tool(\n \"search_code\",\n dedent`\n Searches for code that matches the provided search query as a substring by default, or as a regular expression if useRegex is true. Useful for exploring remote repositories by searching for exact symbols, functions, variables, or specific code patterns. To determine if a repository is indexed, use the \\`list_repos\\` tool. By default, searches are global and will search the default branch of all repositories. Searches can be scoped to specific repositories, languages, and branches. When referencing code outputted by this tool, always include the file's external URL as a link. This makes it easier for the user to view the file, even if they don't have it locally checked out.\n `,\n {\n query: z\n .string()\n .describe(`The search pattern to match against code contents. Do not escape quotes in your query.`)\n // Escape backslashes first, then quotes, and wrap in double quotes\n // so the query is treated as a literal phrase (like grep).\n .transform((val) => {\n const escaped = val.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n return `\"${escaped}\"`;\n }),\n useRegex: z\n .boolean()\n .describe(`Whether to use regular expression matching to match the search query against code contents. When false, substring matching is used. (default: false)`)\n .optional(),\n filterByRepos: z\n .array(z.string())\n .describe(`Scope the search to the provided repositories.`)\n .optional(),\n filterByLanguages: z\n .array(z.string())\n .describe(`Scope the search to the provided languages.`)\n .optional(),\n filterByFilepaths: z\n .array(z.string())\n .describe(`Scope the search to the provided filepaths.`)\n .optional(),\n caseSensitive: z\n .boolean()\n .describe(`Whether the search should be case sensitive (default: false).`)\n .optional(),\n includeCodeSnippets: z\n .boolean()\n .describe(`Whether to include the code snippets in the response. If false, only the file's URL, repository, and language will be returned. (default: false)`)\n .optional(),\n ref: z\n .string()\n .describe(`Commit SHA, branch or tag name to search on. If not provided, defaults to the default branch (usually 'main' or 'master').`)\n .optional(),\n maxTokens: numberSchema\n .describe(`The maximum number of tokens to return (default: ${env.DEFAULT_MINIMUM_TOKENS}). Higher values provide more context but consume more tokens. Values less than ${env.DEFAULT_MINIMUM_TOKENS} will be ignored.`)\n .transform((val) => (val < env.DEFAULT_MINIMUM_TOKENS ? env.DEFAULT_MINIMUM_TOKENS : val))\n .optional(),\n },\n async ({\n query,\n filterByRepos: repos = [],\n filterByLanguages: languages = [],\n filterByFilepaths: filepaths = [],\n maxTokens = env.DEFAULT_MINIMUM_TOKENS,\n includeCodeSnippets = false,\n caseSensitive = false,\n ref,\n useRegex = false,\n }) => {\n if (repos.length > 0) {\n query += ` (repo:${repos.map(id => escapeStringRegexp(id)).join(' or repo:')})`;\n }\n\n if (languages.length > 0) {\n query += ` (lang:${languages.join(' or lang:')})`;\n }\n\n if (filepaths.length > 0) {\n query += ` (file:${filepaths.map(filepath => escapeStringRegexp(filepath)).join(' or file:')})`;\n }\n\n if (ref) {\n query += ` ( rev:${ref} )`;\n }\n\n const response = await search({\n query,\n matches: env.DEFAULT_MATCHES,\n contextLines: env.DEFAULT_CONTEXT_LINES,\n isRegexEnabled: useRegex,\n isCaseSensitivityEnabled: caseSensitive,\n });\n\n if (response.files.length === 0) {\n return {\n content: [{\n type: \"text\",\n text: `No results found for the query: ${query}`,\n }],\n };\n }\n\n const content: TextContent[] = [];\n let totalTokens = 0;\n let isResponseTruncated = false;\n\n for (const file of response.files) {\n const numMatches = file.chunks.reduce(\n (acc, chunk) => acc + chunk.matchRanges.length,\n 0,\n );\n let text = dedent`\n file: ${file.webUrl}\n num_matches: ${numMatches}\n repo: ${file.repository}\n language: ${file.language}\n `;\n\n if (includeCodeSnippets) {\n const snippets = file.chunks.map(chunk => {\n return `\\`\\`\\`\\n${chunk.content}\\n\\`\\`\\``\n }).join('\\n');\n text += `\\n\\n${snippets}`;\n }\n\n\n // Rough estimate of the number of tokens in the text\n // @see: https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them\n const tokens = text.length / 4;\n\n if ((totalTokens + tokens) > maxTokens) {\n // Calculate remaining token budget\n const remainingTokens = maxTokens - totalTokens;\n\n if (remainingTokens > 100) { // Only truncate if meaningful space left\n // Truncate text to fit remaining tokens (tokens ≈ chars/4)\n const maxLength = Math.floor(remainingTokens * 4);\n const truncatedText = text.substring(0, maxLength) + \"\\n\\n...[content truncated due to token limit]\";\n\n content.push({\n type: \"text\",\n text: truncatedText,\n });\n\n totalTokens += remainingTokens;\n }\n\n isResponseTruncated = true;\n break;\n }\n\n totalTokens += tokens;\n content.push({\n type: \"text\",\n text,\n });\n }\n\n if (isResponseTruncated) {\n content.push({\n type: \"text\",\n text: `The response was truncated because the number of tokens exceeded the maximum limit of ${maxTokens}.`,\n });\n }\n\n return {\n content,\n }\n }\n);\n\nserver.tool(\n \"list_commits\",\n dedent`Get a list of commits for a given repository.`,\n listCommitsQueryParamsSchema.shape,\n async (request: ListCommitsQueryParamsSchema) => {\n const result = await listCommits(request);\n\n return {\n content: [{\n type: \"text\", text: JSON.stringify(result)\n }],\n };\n }\n);\n\nserver.tool(\n \"list_repos\",\n dedent`Lists repositories in the organization with optional filtering and pagination.`,\n listReposQueryParamsSchema.shape,\n async (request: ListReposQueryParams) => {\n const result = await listRepos(request);\n\n return {\n content: [{\n type: \"text\", text: JSON.stringify({\n repos: result.repos.map((repo) => ({\n name: repo.repoName,\n url: repo.webUrl,\n pushedAt: repo.pushedAt,\n })),\n totalCount: result.totalCount,\n })\n }]\n };\n }\n);\n\nserver.tool(\n \"read_file\",\n dedent`Reads the source code for a given file.`,\n fileSourceRequestSchema.shape,\n async (request: FileSourceRequest) => {\n const response = await getFileSource(request);\n\n return {\n content: [{\n type: \"text\", text: JSON.stringify({\n source: response.source,\n language: response.language,\n path: response.path,\n url: response.webUrl,\n })\n }]\n };\n }\n);\n\nserver.tool(\n \"list_tree\",\n dedent`\n Lists files and directories from a repository path. This can be used as a repo tree tool or directory listing tool.\n Returns a flat list of entries with path metadata and depth relative to the requested path.\n `,\n listTreeRequestSchema.shape,\n async ({\n repo,\n path = '',\n ref = 'HEAD',\n depth = DEFAULT_TREE_DEPTH,\n includeFiles = true,\n includeDirectories = true,\n maxEntries = DEFAULT_MAX_TREE_ENTRIES,\n }: ListTreeRequest) => {\n const normalizedPath = normalizeTreePath(path);\n const normalizedDepth = Math.min(depth, MAX_TREE_DEPTH);\n const normalizedMaxEntries = Math.min(maxEntries, MAX_MAX_TREE_ENTRIES);\n\n if (!includeFiles && !includeDirectories) {\n return {\n content: [{\n type: \"text\",\n text: JSON.stringify({\n repo,\n ref,\n path: normalizedPath,\n entries: [] as ListTreeEntry[],\n totalReturned: 0,\n truncated: false,\n }),\n }],\n };\n }\n\n // BFS frontier of directories still to expand. Each item stores a repo-relative\n // directory path plus the current depth from the requested root `path`.\n const queue: Array<{ path: string; depth: number }> = [{ path: normalizedPath, depth: 0 }];\n\n // Tracks directory paths that have already been enqueued.\n // With the current single-root traversal duplicates are uncommon, but this\n // prevents duplicate expansion if we later support overlapping multi-root\n // inputs (e.g. [\"src\", \"src/lib\"]) or receive overlapping tree data.\n const queuedPaths = new Set<string>([normalizedPath]);\n\n const seenEntries = new Set<string>();\n const entries: ListTreeEntry[] = [];\n let truncated = false;\n\n // Traverse breadth-first by depth, batching all directories at the same\n // depth into a single /api/tree request per iteration.\n while (queue.length > 0 && !truncated) {\n const currentDepth = queue[0]!.depth;\n const currentLevelPaths: string[] = [];\n\n // Drain only the current depth level so we can issue one API call\n // for all sibling directories before moving deeper.\n while (queue.length > 0 && queue[0]!.depth === currentDepth) {\n const next = queue.shift()!;\n currentLevelPaths.push(next.path);\n }\n\n // Ask Sourcebot for a tree spanning all requested paths at this level.\n const treeResponse = await listTree({\n repoName: repo,\n revisionName: ref,\n paths: currentLevelPaths.filter(Boolean),\n });\n const treeNodeIndex = buildTreeNodeIndex(treeResponse.tree);\n\n for (const currentPath of currentLevelPaths) {\n const currentNode = currentPath === '' ? treeResponse.tree : treeNodeIndex.get(currentPath);\n if (!currentNode || currentNode.type !== 'tree') {\n // Skip paths that are missing from the response or resolve to a\n // file node. We only iterate children of directories.\n continue;\n }\n\n for (const child of currentNode.children) {\n if (child.type !== 'tree' && child.type !== 'blob') {\n // Skip non-standard git object types (e.g. unexpected entries)\n // since this tool only exposes directories and files.\n continue;\n }\n\n const childPath = joinTreePath(currentPath, child.name);\n const childDepth = currentDepth + 1;\n\n // Queue child directories for the next depth level only if\n // they are within the requested depth bound.\n if (child.type === 'tree' && childDepth < normalizedDepth && !queuedPaths.has(childPath)) {\n queue.push({ path: childPath, depth: childDepth });\n queuedPaths.add(childPath);\n }\n\n if ((child.type === 'blob' && !includeFiles) || (child.type === 'tree' && !includeDirectories)) {\n // Skip entries filtered out by caller preferences\n // (`includeFiles` / `includeDirectories`).\n continue;\n }\n\n const key = `${child.type}:${childPath}`;\n if (seenEntries.has(key)) {\n // Skip duplicates when multiple requested paths overlap and\n // surface the same child entry.\n continue;\n }\n seenEntries.add(key);\n\n // Stop collecting once the entry budget is exhausted.\n if (entries.length >= normalizedMaxEntries) {\n truncated = true;\n break;\n }\n\n entries.push({\n type: child.type,\n path: childPath,\n name: child.name,\n parentPath: currentPath,\n depth: childDepth,\n });\n }\n\n if (truncated) {\n break;\n }\n }\n }\n\n const sortedEntries = sortTreeEntries(entries);\n\n return {\n content: [{\n type: \"text\",\n text: JSON.stringify({\n repo,\n ref,\n path: normalizedPath,\n entries: sortedEntries,\n totalReturned: sortedEntries.length,\n truncated,\n }),\n }]\n };\n }\n);\n\nserver.tool(\n \"list_language_models\",\n dedent`Lists the available language models configured on the Sourcebot instance. Use this to discover which models can be specified when calling ask_codebase.`,\n {},\n async () => {\n const models = await listLanguageModels();\n\n return {\n content: [{\n type: \"text\",\n text: JSON.stringify(models),\n }],\n };\n }\n);\n\nserver.tool(\n \"ask_codebase\",\n dedent`\n Ask a natural language question about the codebase. This tool uses an AI agent to autonomously search code, read files, and find symbol references/definitions to answer your question.\n\n The agent will:\n - Analyze your question and determine what context it needs\n - Search the codebase using multiple strategies (code search, symbol lookup, file reading)\n - Synthesize findings into a comprehensive answer with code references\n\n Returns a detailed answer in markdown format with code references, plus a link to view the full research session (including all tool calls and reasoning) in the Sourcebot web UI.\n\n This is a blocking operation that may take 30-60+ seconds for complex questions as the agent researches the codebase.\n `,\n askCodebaseRequestSchema.shape,\n async (request: AskCodebaseRequest) => {\n const response = await askCodebase(request);\n\n // Format the response with the answer and a link to the chat\n const formattedResponse = dedent`\n ${response.answer}\n\n ---\n **View full research session:** ${response.chatUrl}\n **Model used:** ${response.languageModel.model}\n `;\n\n return {\n content: [{\n type: \"text\",\n text: formattedResponse,\n }],\n };\n }\n);\n\nconst runServer = async () => {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n}\n\nrunServer().catch((error) => {\n console.error('Failed to start MCP server:', error);\n process.exit(1);\n});\n"]}
|
|
1
|
+
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ACpB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\n// Entry point for the MCP server\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport _dedent from \"dedent\";\nimport escapeStringRegexp from 'escape-string-regexp';\nimport { z } from 'zod';\nimport { askCodebase, getFileSource, listCommits, listLanguageModels, listRepos, listTree, search } from './client.js';\nimport { env, numberSchema } from './env.js';\nimport { askCodebaseRequestSchema, DEFAULT_MAX_TREE_ENTRIES, DEFAULT_TREE_DEPTH, fileSourceRequestSchema, listCommitsQueryParamsSchema, listReposQueryParamsSchema, listTreeRequestSchema, MAX_MAX_TREE_ENTRIES, MAX_TREE_DEPTH } from './schemas.js';\nimport { AskCodebaseRequest, FileSourceRequest, ListCommitsQueryParamsSchema, ListReposQueryParams, ListTreeEntry, ListTreeRequest, TextContent } from './types.js';\nimport { buildTreeNodeIndex, joinTreePath, normalizeTreePath, sortTreeEntries } from './utils.js';\n\nconst dedent = _dedent.withOptions({ alignValues: true });\n\n// Create MCP server\nconst server = new McpServer({\n name: 'sourcebot-mcp-server',\n version: '0.1.0',\n});\n\n\nserver.tool(\n \"search_code\",\n dedent`\n Searches for code that matches the provided search query as a substring by default, or as a regular expression if useRegex is true. Useful for exploring remote repositories by searching for exact symbols, functions, variables, or specific code patterns. To determine if a repository is indexed, use the \\`list_repos\\` tool. By default, searches are global and will search the default branch of all repositories. Searches can be scoped to specific repositories, languages, and branches. When referencing code outputted by this tool, always include the file's external URL as a link. This makes it easier for the user to view the file, even if they don't have it locally checked out.\n `,\n {\n query: z\n .string()\n .describe(`The search pattern to match against code contents. Do not escape quotes in your query.`)\n // Escape backslashes first, then quotes, and wrap in double quotes\n // so the query is treated as a literal phrase (like grep).\n .transform((val) => {\n const escaped = val.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n return `\"${escaped}\"`;\n }),\n useRegex: z\n .boolean()\n .describe(`Whether to use regular expression matching to match the search query against code contents. When false, substring matching is used. (default: false)`)\n .optional(),\n filterByRepos: z\n .array(z.string())\n .describe(`Scope the search to the provided repositories.`)\n .optional(),\n filterByLanguages: z\n .array(z.string())\n .describe(`Scope the search to the provided languages.`)\n .optional(),\n filterByFilepaths: z\n .array(z.string())\n .describe(`Scope the search to the provided filepaths.`)\n .optional(),\n caseSensitive: z\n .boolean()\n .describe(`Whether the search should be case sensitive (default: false).`)\n .optional(),\n includeCodeSnippets: z\n .boolean()\n .describe(`Whether to include the code snippets in the response. If false, only the file's URL, repository, and language will be returned. (default: false)`)\n .optional(),\n ref: z\n .string()\n .describe(`Commit SHA, branch or tag name to search on. If not provided, defaults to the default branch (usually 'main' or 'master').`)\n .optional(),\n maxTokens: numberSchema\n .describe(`The maximum number of tokens to return (default: ${env.DEFAULT_MINIMUM_TOKENS}). Higher values provide more context but consume more tokens. Values less than ${env.DEFAULT_MINIMUM_TOKENS} will be ignored.`)\n .transform((val) => (val < env.DEFAULT_MINIMUM_TOKENS ? env.DEFAULT_MINIMUM_TOKENS : val))\n .optional(),\n },\n async ({\n query,\n filterByRepos: repos = [],\n filterByLanguages: languages = [],\n filterByFilepaths: filepaths = [],\n maxTokens = env.DEFAULT_MINIMUM_TOKENS,\n includeCodeSnippets = false,\n caseSensitive = false,\n ref,\n useRegex = false,\n }) => {\n if (repos.length > 0) {\n query += ` (repo:${repos.map(id => escapeStringRegexp(id)).join(' or repo:')})`;\n }\n\n if (languages.length > 0) {\n query += ` (lang:${languages.join(' or lang:')})`;\n }\n\n if (filepaths.length > 0) {\n query += ` (file:${filepaths.map(filepath => escapeStringRegexp(filepath)).join(' or file:')})`;\n }\n\n if (ref) {\n query += ` ( rev:${ref} )`;\n }\n\n const response = await search({\n query,\n matches: env.DEFAULT_MATCHES,\n contextLines: env.DEFAULT_CONTEXT_LINES,\n isRegexEnabled: useRegex,\n isCaseSensitivityEnabled: caseSensitive,\n });\n\n if (response.files.length === 0) {\n return {\n content: [{\n type: \"text\",\n text: `No results found for the query: ${query}`,\n }],\n };\n }\n\n const content: TextContent[] = [];\n let totalTokens = 0;\n let isResponseTruncated = false;\n\n for (const file of response.files) {\n const numMatches = file.chunks.reduce(\n (acc, chunk) => acc + chunk.matchRanges.length,\n 0,\n );\n let text = dedent`\n file: ${file.webUrl}\n num_matches: ${numMatches}\n repo: ${file.repository}\n language: ${file.language}\n `;\n\n if (includeCodeSnippets) {\n const snippets = file.chunks.map(chunk => {\n return `\\`\\`\\`\\n${chunk.content}\\n\\`\\`\\``\n }).join('\\n');\n text += `\\n\\n${snippets}`;\n }\n\n\n // Rough estimate of the number of tokens in the text\n // @see: https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them\n const tokens = text.length / 4;\n\n if ((totalTokens + tokens) > maxTokens) {\n // Calculate remaining token budget\n const remainingTokens = maxTokens - totalTokens;\n\n if (remainingTokens > 100) { // Only truncate if meaningful space left\n // Truncate text to fit remaining tokens (tokens ≈ chars/4)\n const maxLength = Math.floor(remainingTokens * 4);\n const truncatedText = text.substring(0, maxLength) + \"\\n\\n...[content truncated due to token limit]\";\n\n content.push({\n type: \"text\",\n text: truncatedText,\n });\n\n totalTokens += remainingTokens;\n }\n\n isResponseTruncated = true;\n break;\n }\n\n totalTokens += tokens;\n content.push({\n type: \"text\",\n text,\n });\n }\n\n if (isResponseTruncated) {\n content.push({\n type: \"text\",\n text: `The response was truncated because the number of tokens exceeded the maximum limit of ${maxTokens}.`,\n });\n }\n\n return {\n content,\n }\n }\n);\n\nserver.tool(\n \"list_commits\",\n dedent`Get a list of commits for a given repository.`,\n listCommitsQueryParamsSchema.shape,\n async (request: ListCommitsQueryParamsSchema) => {\n const result = await listCommits(request);\n\n return {\n content: [{\n type: \"text\", text: JSON.stringify(result)\n }],\n };\n }\n);\n\nserver.tool(\n \"list_repos\",\n dedent`Lists repositories in the organization with optional filtering and pagination.`,\n listReposQueryParamsSchema.shape,\n async (request: ListReposQueryParams) => {\n const result = await listRepos(request);\n\n return {\n content: [{\n type: \"text\", text: JSON.stringify({\n repos: result.repos.map((repo) => ({\n name: repo.repoName,\n url: repo.webUrl,\n pushedAt: repo.pushedAt,\n defaultBranch: repo.defaultBranch,\n isFork: repo.isFork,\n isArchived: repo.isArchived,\n })),\n totalCount: result.totalCount,\n })\n }]\n };\n }\n);\n\nserver.tool(\n \"read_file\",\n dedent`Reads the source code for a given file.`,\n fileSourceRequestSchema.shape,\n async (request: FileSourceRequest) => {\n const response = await getFileSource(request);\n\n return {\n content: [{\n type: \"text\", text: JSON.stringify({\n source: response.source,\n language: response.language,\n path: response.path,\n url: response.webUrl,\n })\n }]\n };\n }\n);\n\nserver.tool(\n \"list_tree\",\n dedent`\n Lists files and directories from a repository path. This can be used as a repo tree tool or directory listing tool.\n Returns a flat list of entries with path metadata and depth relative to the requested path.\n `,\n listTreeRequestSchema.shape,\n async ({\n repo,\n path = '',\n ref = 'HEAD',\n depth = DEFAULT_TREE_DEPTH,\n includeFiles = true,\n includeDirectories = true,\n maxEntries = DEFAULT_MAX_TREE_ENTRIES,\n }: ListTreeRequest) => {\n const normalizedPath = normalizeTreePath(path);\n const normalizedDepth = Math.min(depth, MAX_TREE_DEPTH);\n const normalizedMaxEntries = Math.min(maxEntries, MAX_MAX_TREE_ENTRIES);\n\n if (!includeFiles && !includeDirectories) {\n return {\n content: [{\n type: \"text\",\n text: JSON.stringify({\n repo,\n ref,\n path: normalizedPath,\n entries: [] as ListTreeEntry[],\n totalReturned: 0,\n truncated: false,\n }),\n }],\n };\n }\n\n // BFS frontier of directories still to expand. Each item stores a repo-relative\n // directory path plus the current depth from the requested root `path`.\n const queue: Array<{ path: string; depth: number }> = [{ path: normalizedPath, depth: 0 }];\n\n // Tracks directory paths that have already been enqueued.\n // With the current single-root traversal duplicates are uncommon, but this\n // prevents duplicate expansion if we later support overlapping multi-root\n // inputs (e.g. [\"src\", \"src/lib\"]) or receive overlapping tree data.\n const queuedPaths = new Set<string>([normalizedPath]);\n\n const seenEntries = new Set<string>();\n const entries: ListTreeEntry[] = [];\n let truncated = false;\n\n // Traverse breadth-first by depth, batching all directories at the same\n // depth into a single /api/tree request per iteration.\n while (queue.length > 0 && !truncated) {\n const currentDepth = queue[0]!.depth;\n const currentLevelPaths: string[] = [];\n\n // Drain only the current depth level so we can issue one API call\n // for all sibling directories before moving deeper.\n while (queue.length > 0 && queue[0]!.depth === currentDepth) {\n const next = queue.shift()!;\n currentLevelPaths.push(next.path);\n }\n\n // Ask Sourcebot for a tree spanning all requested paths at this level.\n const treeResponse = await listTree({\n repoName: repo,\n revisionName: ref,\n paths: currentLevelPaths.filter(Boolean),\n });\n const treeNodeIndex = buildTreeNodeIndex(treeResponse.tree);\n\n for (const currentPath of currentLevelPaths) {\n const currentNode = currentPath === '' ? treeResponse.tree : treeNodeIndex.get(currentPath);\n if (!currentNode || currentNode.type !== 'tree') {\n // Skip paths that are missing from the response or resolve to a\n // file node. We only iterate children of directories.\n continue;\n }\n\n for (const child of currentNode.children) {\n if (child.type !== 'tree' && child.type !== 'blob') {\n // Skip non-standard git object types (e.g. unexpected entries)\n // since this tool only exposes directories and files.\n continue;\n }\n\n const childPath = joinTreePath(currentPath, child.name);\n const childDepth = currentDepth + 1;\n\n // Queue child directories for the next depth level only if\n // they are within the requested depth bound.\n if (child.type === 'tree' && childDepth < normalizedDepth && !queuedPaths.has(childPath)) {\n queue.push({ path: childPath, depth: childDepth });\n queuedPaths.add(childPath);\n }\n\n if ((child.type === 'blob' && !includeFiles) || (child.type === 'tree' && !includeDirectories)) {\n // Skip entries filtered out by caller preferences\n // (`includeFiles` / `includeDirectories`).\n continue;\n }\n\n const key = `${child.type}:${childPath}`;\n if (seenEntries.has(key)) {\n // Skip duplicates when multiple requested paths overlap and\n // surface the same child entry.\n continue;\n }\n seenEntries.add(key);\n\n // Stop collecting once the entry budget is exhausted.\n if (entries.length >= normalizedMaxEntries) {\n truncated = true;\n break;\n }\n\n entries.push({\n type: child.type,\n path: childPath,\n name: child.name,\n parentPath: currentPath,\n depth: childDepth,\n });\n }\n\n if (truncated) {\n break;\n }\n }\n }\n\n const sortedEntries = sortTreeEntries(entries);\n\n return {\n content: [{\n type: \"text\",\n text: JSON.stringify({\n repo,\n ref,\n path: normalizedPath,\n entries: sortedEntries,\n totalReturned: sortedEntries.length,\n truncated,\n }),\n }]\n };\n }\n);\n\nserver.tool(\n \"list_language_models\",\n dedent`Lists the available language models configured on the Sourcebot instance. Use this to discover which models can be specified when calling ask_codebase.`,\n {},\n async () => {\n const models = await listLanguageModels();\n\n return {\n content: [{\n type: \"text\",\n text: JSON.stringify(models),\n }],\n };\n }\n);\n\nserver.tool(\n \"ask_codebase\",\n dedent`\n Ask a natural language question about the codebase. This tool uses an AI agent to autonomously search code, read files, and find symbol references/definitions to answer your question.\n\n The agent will:\n - Analyze your question and determine what context it needs\n - Search the codebase using multiple strategies (code search, symbol lookup, file reading)\n - Synthesize findings into a comprehensive answer with code references\n\n Returns a detailed answer in markdown format with code references, plus a link to view the full research session (including all tool calls and reasoning) in the Sourcebot web UI.\n\n When using this in shared environments (e.g., Slack), you can set the visibility parameter to 'PUBLIC' to ensure everyone can access the chat link.\n\n This is a blocking operation that may take 30-60+ seconds for complex questions as the agent researches the codebase.\n `,\n askCodebaseRequestSchema.shape,\n async (request: AskCodebaseRequest) => {\n const response = await askCodebase(request);\n\n // Format the response with the answer and a link to the chat\n const formattedResponse = dedent`\n ${response.answer}\n\n ---\n **View full research session:** ${response.chatUrl}\n **Model used:** ${response.languageModel.model}\n `;\n\n return {\n content: [{\n type: \"text\",\n text: formattedResponse,\n }],\n };\n }\n);\n\nconst runServer = async () => {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n}\n\nrunServer().catch((error) => {\n console.error('Failed to start MCP server:', error);\n process.exit(1);\n});\n"]}
|