@sourcebot/mcp 1.0.14 → 1.0.15
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 +6 -0
- package/README.md +26 -0
- package/dist/client.d.ts +16 -3
- package/dist/client.js +40 -1
- package/dist/client.js.map +1 -1
- package/dist/index.js +39 -3
- package/dist/index.js.map +1 -1
- package/dist/schemas.d.ts +115 -8
- package/dist/schemas.js +37 -2
- package/dist/schemas.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +5 -1
- package/dist/types.js.map +1 -1
- package/package.json +45 -41
- package/Dockerfile +0 -27
- package/smithery.yaml +0 -24
- package/tsconfig.json +0 -28
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.0.15] - 2026-02-02
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Added `ask_codebase` tool that can invoke the Ask subagent to explore a set of codebases and return a summarized answer. [#814](https://github.com/sourcebot-dev/sourcebot/pull/814)
|
|
14
|
+
- Added `list_language_models` tool to discover available language models configured on the Sourcebot instance. [#814](https://github.com/sourcebot-dev/sourcebot/pull/814)
|
|
15
|
+
|
|
10
16
|
## [1.0.14] - 2026-01-27
|
|
11
17
|
|
|
12
18
|
### Changed
|
package/README.md
CHANGED
|
@@ -234,6 +234,32 @@ Get a list of commits for a given repository.
|
|
|
234
234
|
|
|
235
235
|
</details>
|
|
236
236
|
|
|
237
|
+
### list_language_models
|
|
238
|
+
|
|
239
|
+
Lists the available language models configured on the Sourcebot instance. Use this to discover which models can be specified when calling `ask_codebase`.
|
|
240
|
+
|
|
241
|
+
<details>
|
|
242
|
+
<summary>Parameters</summary>
|
|
243
|
+
|
|
244
|
+
This tool takes no parameters.
|
|
245
|
+
|
|
246
|
+
</details>
|
|
247
|
+
|
|
248
|
+
### ask_codebase
|
|
249
|
+
|
|
250
|
+
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. Returns a detailed answer in markdown format with code references, plus a link to view the full research session in the Sourcebot web UI.
|
|
251
|
+
|
|
252
|
+
<details>
|
|
253
|
+
<summary>Parameters</summary>
|
|
254
|
+
|
|
255
|
+
| Name | Required | Description |
|
|
256
|
+
|:----------------|:---------|:-----------------------------------------------------------------------------------------------------------------------------------------------|
|
|
257
|
+
| `query` | yes | The query to ask about the codebase. |
|
|
258
|
+
| `repos` | no | The repositories that are accessible to the agent during the chat. If not provided, all repositories are accessible. |
|
|
259
|
+
| `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. |
|
|
260
|
+
|
|
261
|
+
</details>
|
|
262
|
+
|
|
237
263
|
|
|
238
264
|
## Supported Code Hosts
|
|
239
265
|
Sourcebot supports the following code hosts:
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FileSourceRequest, ListReposQueryParams, SearchRequest, ListCommitsQueryParamsSchema } from './types.js';
|
|
1
|
+
import { AskCodebaseRequest, AskCodebaseResponse, FileSourceRequest, ListReposQueryParams, SearchRequest, ListCommitsQueryParamsSchema, ListLanguageModelsResponse } from './types.js';
|
|
2
2
|
export declare const search: (request: SearchRequest) => Promise<{
|
|
3
3
|
stats: {
|
|
4
4
|
actualMatchCount: number;
|
|
@@ -100,15 +100,14 @@ export declare const listRepos: (queryParams?: ListReposQueryParams) => Promise<
|
|
|
100
100
|
}>;
|
|
101
101
|
export declare const getFileSource: (request: FileSourceRequest) => Promise<{
|
|
102
102
|
path: string;
|
|
103
|
-
source: string;
|
|
104
103
|
webUrl: string;
|
|
105
104
|
language: string;
|
|
106
105
|
repo: string;
|
|
106
|
+
source: string;
|
|
107
107
|
repoCodeHostType: string;
|
|
108
108
|
externalWebUrl?: string | undefined;
|
|
109
109
|
repoDisplayName?: string | undefined;
|
|
110
110
|
repoExternalWebUrl?: string | undefined;
|
|
111
|
-
branch?: string | undefined;
|
|
112
111
|
}>;
|
|
113
112
|
export declare const listCommits: (queryParams: ListCommitsQueryParamsSchema) => Promise<{
|
|
114
113
|
commits: {
|
|
@@ -122,3 +121,17 @@ export declare const listCommits: (queryParams: ListCommitsQueryParamsSchema) =>
|
|
|
122
121
|
}[];
|
|
123
122
|
totalCount: number;
|
|
124
123
|
}>;
|
|
124
|
+
/**
|
|
125
|
+
* Asks a natural language question about the codebase using the Sourcebot AI agent.
|
|
126
|
+
* This is a blocking call that runs the full agent loop and returns when complete.
|
|
127
|
+
*
|
|
128
|
+
* @param request - The question and optional repo filters
|
|
129
|
+
* @returns The agent's answer, chat URL, sources, and metadata
|
|
130
|
+
*/
|
|
131
|
+
export declare const askCodebase: (request: AskCodebaseRequest) => Promise<AskCodebaseResponse>;
|
|
132
|
+
/**
|
|
133
|
+
* Lists the available language models configured on the Sourcebot instance.
|
|
134
|
+
*
|
|
135
|
+
* @returns Array of language model info objects
|
|
136
|
+
*/
|
|
137
|
+
export declare const listLanguageModels: () => Promise<ListLanguageModelsResponse>;
|
package/dist/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { env } from './env.js';
|
|
2
|
-
import { listReposResponseSchema, searchResponseSchema, fileSourceResponseSchema, listCommitsResponseSchema } from './schemas.js';
|
|
2
|
+
import { listReposResponseSchema, searchResponseSchema, fileSourceResponseSchema, listCommitsResponseSchema, askCodebaseResponseSchema, listLanguageModelsResponseSchema } from './schemas.js';
|
|
3
3
|
import { isServiceError, ServiceErrorException } from './utils.js';
|
|
4
4
|
const parseResponse = async (response, schema) => {
|
|
5
5
|
const text = await response.text();
|
|
@@ -25,6 +25,7 @@ export const search = async (request) => {
|
|
|
25
25
|
method: 'POST',
|
|
26
26
|
headers: {
|
|
27
27
|
'Content-Type': 'application/json',
|
|
28
|
+
'X-Sourcebot-Client-Source': 'mcp',
|
|
28
29
|
...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})
|
|
29
30
|
},
|
|
30
31
|
body: JSON.stringify(request)
|
|
@@ -42,6 +43,7 @@ export const listRepos = async (queryParams = {}) => {
|
|
|
42
43
|
method: 'GET',
|
|
43
44
|
headers: {
|
|
44
45
|
'Content-Type': 'application/json',
|
|
46
|
+
'X-Sourcebot-Client-Source': 'mcp',
|
|
45
47
|
...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})
|
|
46
48
|
},
|
|
47
49
|
});
|
|
@@ -59,6 +61,7 @@ export const getFileSource = async (request) => {
|
|
|
59
61
|
const response = await fetch(url, {
|
|
60
62
|
method: 'GET',
|
|
61
63
|
headers: {
|
|
64
|
+
'X-Sourcebot-Client-Source': 'mcp',
|
|
62
65
|
...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})
|
|
63
66
|
},
|
|
64
67
|
});
|
|
@@ -75,6 +78,7 @@ export const listCommits = async (queryParams) => {
|
|
|
75
78
|
method: 'GET',
|
|
76
79
|
headers: {
|
|
77
80
|
'X-Org-Domain': '~',
|
|
81
|
+
'X-Sourcebot-Client-Source': 'mcp',
|
|
78
82
|
...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})
|
|
79
83
|
},
|
|
80
84
|
});
|
|
@@ -82,4 +86,39 @@ export const listCommits = async (queryParams) => {
|
|
|
82
86
|
const totalCount = parseInt(response.headers.get('X-Total-Count') ?? '0', 10);
|
|
83
87
|
return { commits, totalCount };
|
|
84
88
|
};
|
|
89
|
+
/**
|
|
90
|
+
* Asks a natural language question about the codebase using the Sourcebot AI agent.
|
|
91
|
+
* This is a blocking call that runs the full agent loop and returns when complete.
|
|
92
|
+
*
|
|
93
|
+
* @param request - The question and optional repo filters
|
|
94
|
+
* @returns The agent's answer, chat URL, sources, and metadata
|
|
95
|
+
*/
|
|
96
|
+
export const askCodebase = async (request) => {
|
|
97
|
+
const response = await fetch(`${env.SOURCEBOT_HOST}/api/chat/blocking`, {
|
|
98
|
+
method: 'POST',
|
|
99
|
+
headers: {
|
|
100
|
+
'Content-Type': 'application/json',
|
|
101
|
+
'X-Sourcebot-Client-Source': 'mcp',
|
|
102
|
+
...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})
|
|
103
|
+
},
|
|
104
|
+
body: JSON.stringify(request),
|
|
105
|
+
});
|
|
106
|
+
return parseResponse(response, askCodebaseResponseSchema);
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Lists the available language models configured on the Sourcebot instance.
|
|
110
|
+
*
|
|
111
|
+
* @returns Array of language model info objects
|
|
112
|
+
*/
|
|
113
|
+
export const listLanguageModels = async () => {
|
|
114
|
+
const response = await fetch(`${env.SOURCEBOT_HOST}/api/models`, {
|
|
115
|
+
method: 'GET',
|
|
116
|
+
headers: {
|
|
117
|
+
'Content-Type': 'application/json',
|
|
118
|
+
'X-Sourcebot-Client-Source': 'mcp',
|
|
119
|
+
...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
return parseResponse(response, listLanguageModelsResponseSchema);
|
|
123
|
+
};
|
|
85
124
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"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C7D,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACL,cAAc,EAAE,kBAAkB;YAClC,2BAA2B,EAAE,KAAK;YAClC,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACrF;KACJ,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,QAAQ,EAAE,gCAAgC,CAAC,CAAC;AACrE,CAAC,CAAA","sourcesContent":["import { env } from './env.js';\nimport { listReposResponseSchema, searchResponseSchema, fileSourceResponseSchema, listCommitsResponseSchema, askCodebaseResponseSchema, listLanguageModelsResponseSchema } from './schemas.js';\nimport { AskCodebaseRequest, AskCodebaseResponse, FileSourceRequest, ListReposQueryParams, SearchRequest, ListCommitsQueryParamsSchema, ListLanguageModelsResponse } from './types.js';\nimport { isServiceError, ServiceErrorException } from './utils.js';\nimport { z } from 'zod';\n\nconst parseResponse = async <T extends z.ZodTypeAny>(\n response: Response,\n schema: T\n): Promise<z.infer<T>> => {\n const text = await response.text();\n\n let json: unknown;\n try {\n json = JSON.parse(text);\n } catch {\n throw new Error(`Invalid JSON response: ${text}`);\n }\n\n // Check if the response is already a service error from the API\n if (isServiceError(json)) {\n throw new ServiceErrorException(json);\n }\n\n const parsed = schema.safeParse(json);\n if (!parsed.success) {\n throw new Error(`Failed to parse response: ${parsed.error.message}`);\n }\n\n return parsed.data;\n};\n\nexport const search = async (request: SearchRequest) => {\n const response = await fetch(`${env.SOURCEBOT_HOST}/api/search`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Sourcebot-Client-Source': 'mcp',\n ...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})\n },\n body: JSON.stringify(request)\n });\n\n return parseResponse(response, searchResponseSchema);\n}\n\nexport const listRepos = async (queryParams: ListReposQueryParams = {}) => {\n const url = new URL(`${env.SOURCEBOT_HOST}/api/repos`);\n\n for (const [key, value] of Object.entries(queryParams)) {\n if (value) {\n url.searchParams.set(key, value.toString());\n }\n }\n\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Sourcebot-Client-Source': 'mcp',\n ...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})\n },\n });\n\n const repos = await parseResponse(response, listReposResponseSchema);\n const totalCount = parseInt(response.headers.get('X-Total-Count') ?? '0', 10);\n return { repos, totalCount };\n}\n\nexport const getFileSource = async (request: FileSourceRequest) => {\n const url = new URL(`${env.SOURCEBOT_HOST}/api/source`);\n for (const [key, value] of Object.entries(request)) {\n if (value) {\n url.searchParams.set(key, value.toString());\n }\n }\n\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'X-Sourcebot-Client-Source': 'mcp',\n ...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})\n },\n });\n\n return parseResponse(response, fileSourceResponseSchema);\n}\n\nexport const listCommits = async (queryParams: ListCommitsQueryParamsSchema) => {\n const url = new URL(`${env.SOURCEBOT_HOST}/api/commits`);\n for (const [key, value] of Object.entries(queryParams)) {\n if (value) {\n url.searchParams.set(key, value.toString());\n }\n }\n\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'X-Org-Domain': '~',\n 'X-Sourcebot-Client-Source': 'mcp',\n ...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})\n },\n });\n\n const commits = await parseResponse(response, listCommitsResponseSchema);\n const totalCount = parseInt(response.headers.get('X-Total-Count') ?? '0', 10);\n return { commits, totalCount };\n}\n\n/**\n * Asks a natural language question about the codebase using the Sourcebot AI agent.\n * This is a blocking call that runs the full agent loop and returns when complete.\n *\n * @param request - The question and optional repo filters\n * @returns The agent's answer, chat URL, sources, and metadata\n */\nexport const askCodebase = async (request: AskCodebaseRequest): Promise<AskCodebaseResponse> => {\n const response = await fetch(`${env.SOURCEBOT_HOST}/api/chat/blocking`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Sourcebot-Client-Source': 'mcp',\n ...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})\n },\n body: JSON.stringify(request),\n });\n\n return parseResponse(response, askCodebaseResponseSchema);\n}\n\n/**\n * Lists the available language models configured on the Sourcebot instance.\n *\n * @returns Array of language model info objects\n */\nexport const listLanguageModels = async (): Promise<ListLanguageModelsResponse> => {\n const response = await fetch(`${env.SOURCEBOT_HOST}/api/models`, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Sourcebot-Client-Source': 'mcp',\n ...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})\n },\n });\n\n return parseResponse(response, listLanguageModelsResponseSchema);\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -5,9 +5,9 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
5
5
|
import _dedent from "dedent";
|
|
6
6
|
import escapeStringRegexp from 'escape-string-regexp';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { getFileSource, listCommits, listRepos, search } from './client.js';
|
|
8
|
+
import { askCodebase, getFileSource, listCommits, listLanguageModels, listRepos, search } from './client.js';
|
|
9
9
|
import { env, numberSchema } from './env.js';
|
|
10
|
-
import { fileSourceRequestSchema, listCommitsQueryParamsSchema, listReposQueryParamsSchema } from './schemas.js';
|
|
10
|
+
import { askCodebaseRequestSchema, fileSourceRequestSchema, listCommitsQueryParamsSchema, listReposQueryParamsSchema } from './schemas.js';
|
|
11
11
|
const dedent = _dedent.withOptions({ alignValues: true });
|
|
12
12
|
// Create MCP server
|
|
13
13
|
const server = new McpServer({
|
|
@@ -77,7 +77,6 @@ server.tool("search_code", dedent `
|
|
|
77
77
|
contextLines: env.DEFAULT_CONTEXT_LINES,
|
|
78
78
|
isRegexEnabled: useRegex,
|
|
79
79
|
isCaseSensitivityEnabled: caseSensitive,
|
|
80
|
-
source: 'mcp',
|
|
81
80
|
});
|
|
82
81
|
if (response.files.length === 0) {
|
|
83
82
|
return {
|
|
@@ -175,6 +174,43 @@ server.tool("read_file", dedent `Reads the source code for a given file.`, fileS
|
|
|
175
174
|
}]
|
|
176
175
|
};
|
|
177
176
|
});
|
|
177
|
+
server.tool("list_language_models", dedent `Lists the available language models configured on the Sourcebot instance. Use this to discover which models can be specified when calling ask_codebase.`, {}, async () => {
|
|
178
|
+
const models = await listLanguageModels();
|
|
179
|
+
return {
|
|
180
|
+
content: [{
|
|
181
|
+
type: "text",
|
|
182
|
+
text: JSON.stringify(models),
|
|
183
|
+
}],
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
server.tool("ask_codebase", dedent `
|
|
187
|
+
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.
|
|
188
|
+
|
|
189
|
+
The agent will:
|
|
190
|
+
- Analyze your question and determine what context it needs
|
|
191
|
+
- Search the codebase using multiple strategies (code search, symbol lookup, file reading)
|
|
192
|
+
- Synthesize findings into a comprehensive answer with code references
|
|
193
|
+
|
|
194
|
+
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.
|
|
195
|
+
|
|
196
|
+
This is a blocking operation that may take 30-60+ seconds for complex questions as the agent researches the codebase.
|
|
197
|
+
`, askCodebaseRequestSchema.shape, async (request) => {
|
|
198
|
+
const response = await askCodebase(request);
|
|
199
|
+
// Format the response with the answer and a link to the chat
|
|
200
|
+
const formattedResponse = dedent `
|
|
201
|
+
${response.answer}
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
**View full research session:** ${response.chatUrl}
|
|
205
|
+
**Model used:** ${response.languageModel.model}
|
|
206
|
+
`;
|
|
207
|
+
return {
|
|
208
|
+
content: [{
|
|
209
|
+
type: "text",
|
|
210
|
+
text: formattedResponse,
|
|
211
|
+
}],
|
|
212
|
+
};
|
|
213
|
+
});
|
|
178
214
|
const runServer = async () => {
|
|
179
215
|
const transport = new StdioServerTransport();
|
|
180
216
|
await server.connect(transport);
|
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,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAGjH,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;AAE1D,oBAAoB;AACpB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IACzB,IAAI,EAAE,sBAAsB;IAC5B,OAAO,EAAE,OAAO;CACnB,CAAC,CAAC;AAGH,MAAM,CAAC,IAAI,CACP,aAAa,EACb,MAAM,CAAA;;KAEL,EACD;IACI,KAAK,EAAE,CAAC;SACH,MAAM,EAAE;SACR,QAAQ,CAAC,wFAAwF,CAAC;QACnG,mEAAmE;QACnE,2DAA2D;SAC1D,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE;QACf,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC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elcontextprotocol/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 { getFileSource, listCommits, listRepos, search } from './client.js';\nimport { env, numberSchema } from './env.js';\nimport { fileSourceRequestSchema, listCommitsQueryParamsSchema, listReposQueryParamsSchema } from './schemas.js';\nimport { FileSourceRequest, ListCommitsQueryParamsSchema, ListReposQueryParams, TextContent } from './types.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 source: 'mcp',\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\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
|
+
{"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,MAAM,EAAE,MAAM,aAAa,CAAC;AAC7G,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAG3I,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;AAE1D,oBAAoB;AACpB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IACzB,IAAI,EAAE,sBAAsB;IAC5B,OAAO,EAAE,OAAO;CACnB,CAAC,CAAC;AAGH,MAAM,CAAC,IAAI,CACP,aAAa,EACb,MAAM,CAAA;;KAEL,EACD;IACI,KAAK,EAAE,CAAC;SACH,MAAM,EAAE;SACR,QAAQ,CAAC,wFAAwF,CAAC;QACnG,mEAAmE;QACnE,2DAA2D;SAC1D,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE;QACf,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,KAA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;IAClC,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;IAE5C,6DAA6D;IAC7D,MAAM,iBAAiB,GAAG,MAAM,CAAA;UAC9B,QAAQ,CAAC,MAAM;;;0CAGiB,QAAQ,CAAC,OAAO;0BAChC,QAAQ,CAAC,aAAa,CAAC,KAAK;SAC7C,CAAC;IAEF,OAAO;QACH,OAAO,EAAE,CAAC;gBACN,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,iBAAiB;aAC1B,CAAC;KACL,CAAC;AACN,CAAC,CACJ,CAAC;AAEF,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE;IACzB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,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, search } from './client.js';\nimport { env, numberSchema } from './env.js';\nimport { askCodebaseRequestSchema, fileSourceRequestSchema, listCommitsQueryParamsSchema, listReposQueryParamsSchema } from './schemas.js';\nimport { AskCodebaseRequest, FileSourceRequest, ListCommitsQueryParamsSchema, ListReposQueryParams, TextContent } from './types.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_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"]}
|
package/dist/schemas.d.ts
CHANGED
|
@@ -98,7 +98,6 @@ export declare const searchRequestSchema: z.ZodObject<{
|
|
|
98
98
|
isRegexEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
99
99
|
isCaseSensitivityEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
100
100
|
query: z.ZodString;
|
|
101
|
-
source: z.ZodOptional<z.ZodString>;
|
|
102
101
|
}, "strip", z.ZodTypeAny, {
|
|
103
102
|
matches: number;
|
|
104
103
|
query: string;
|
|
@@ -106,7 +105,6 @@ export declare const searchRequestSchema: z.ZodObject<{
|
|
|
106
105
|
whole?: boolean | undefined;
|
|
107
106
|
isRegexEnabled?: boolean | undefined;
|
|
108
107
|
isCaseSensitivityEnabled?: boolean | undefined;
|
|
109
|
-
source?: string | undefined;
|
|
110
108
|
}, {
|
|
111
109
|
matches: number;
|
|
112
110
|
query: string;
|
|
@@ -114,7 +112,6 @@ export declare const searchRequestSchema: z.ZodObject<{
|
|
|
114
112
|
whole?: boolean | undefined;
|
|
115
113
|
isRegexEnabled?: boolean | undefined;
|
|
116
114
|
isCaseSensitivityEnabled?: boolean | undefined;
|
|
117
|
-
source?: string | undefined;
|
|
118
115
|
}>;
|
|
119
116
|
export declare const repositoryInfoSchema: z.ZodObject<{
|
|
120
117
|
id: z.ZodNumber;
|
|
@@ -901,31 +898,28 @@ export declare const fileSourceResponseSchema: z.ZodObject<{
|
|
|
901
898
|
repoCodeHostType: z.ZodString;
|
|
902
899
|
repoDisplayName: z.ZodOptional<z.ZodString>;
|
|
903
900
|
repoExternalWebUrl: z.ZodOptional<z.ZodString>;
|
|
904
|
-
branch: z.ZodOptional<z.ZodString>;
|
|
905
901
|
webUrl: z.ZodString;
|
|
906
902
|
externalWebUrl: z.ZodOptional<z.ZodString>;
|
|
907
903
|
}, "strip", z.ZodTypeAny, {
|
|
908
904
|
path: string;
|
|
909
|
-
source: string;
|
|
910
905
|
webUrl: string;
|
|
911
906
|
language: string;
|
|
912
907
|
repo: string;
|
|
908
|
+
source: string;
|
|
913
909
|
repoCodeHostType: string;
|
|
914
910
|
externalWebUrl?: string | undefined;
|
|
915
911
|
repoDisplayName?: string | undefined;
|
|
916
912
|
repoExternalWebUrl?: string | undefined;
|
|
917
|
-
branch?: string | undefined;
|
|
918
913
|
}, {
|
|
919
914
|
path: string;
|
|
920
|
-
source: string;
|
|
921
915
|
webUrl: string;
|
|
922
916
|
language: string;
|
|
923
917
|
repo: string;
|
|
918
|
+
source: string;
|
|
924
919
|
repoCodeHostType: string;
|
|
925
920
|
externalWebUrl?: string | undefined;
|
|
926
921
|
repoDisplayName?: string | undefined;
|
|
927
922
|
repoExternalWebUrl?: string | undefined;
|
|
928
|
-
branch?: string | undefined;
|
|
929
923
|
}>;
|
|
930
924
|
export declare const serviceErrorSchema: z.ZodObject<{
|
|
931
925
|
statusCode: z.ZodNumber;
|
|
@@ -993,3 +987,116 @@ export declare const listCommitsResponseSchema: z.ZodArray<z.ZodObject<{
|
|
|
993
987
|
author_name: string;
|
|
994
988
|
author_email: string;
|
|
995
989
|
}>, "many">;
|
|
990
|
+
export declare const languageModelInfoSchema: z.ZodObject<{
|
|
991
|
+
provider: z.ZodString;
|
|
992
|
+
model: z.ZodString;
|
|
993
|
+
displayName: z.ZodOptional<z.ZodString>;
|
|
994
|
+
}, "strip", z.ZodTypeAny, {
|
|
995
|
+
provider: string;
|
|
996
|
+
model: string;
|
|
997
|
+
displayName?: string | undefined;
|
|
998
|
+
}, {
|
|
999
|
+
provider: string;
|
|
1000
|
+
model: string;
|
|
1001
|
+
displayName?: string | undefined;
|
|
1002
|
+
}>;
|
|
1003
|
+
export declare const listLanguageModelsResponseSchema: z.ZodArray<z.ZodObject<{
|
|
1004
|
+
provider: z.ZodString;
|
|
1005
|
+
model: z.ZodString;
|
|
1006
|
+
displayName: z.ZodOptional<z.ZodString>;
|
|
1007
|
+
}, "strip", z.ZodTypeAny, {
|
|
1008
|
+
provider: string;
|
|
1009
|
+
model: string;
|
|
1010
|
+
displayName?: string | undefined;
|
|
1011
|
+
}, {
|
|
1012
|
+
provider: string;
|
|
1013
|
+
model: string;
|
|
1014
|
+
displayName?: string | undefined;
|
|
1015
|
+
}>, "many">;
|
|
1016
|
+
export declare const askCodebaseRequestSchema: z.ZodObject<{
|
|
1017
|
+
query: z.ZodString;
|
|
1018
|
+
repos: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
1019
|
+
languageModel: z.ZodOptional<z.ZodObject<Omit<{
|
|
1020
|
+
provider: z.ZodString;
|
|
1021
|
+
model: z.ZodString;
|
|
1022
|
+
displayName: z.ZodOptional<z.ZodString>;
|
|
1023
|
+
}, "displayName">, "strip", z.ZodTypeAny, {
|
|
1024
|
+
provider: string;
|
|
1025
|
+
model: string;
|
|
1026
|
+
}, {
|
|
1027
|
+
provider: string;
|
|
1028
|
+
model: string;
|
|
1029
|
+
}>>;
|
|
1030
|
+
}, "strip", z.ZodTypeAny, {
|
|
1031
|
+
query: string;
|
|
1032
|
+
repos?: string[] | undefined;
|
|
1033
|
+
languageModel?: {
|
|
1034
|
+
provider: string;
|
|
1035
|
+
model: string;
|
|
1036
|
+
} | undefined;
|
|
1037
|
+
}, {
|
|
1038
|
+
query: string;
|
|
1039
|
+
repos?: string[] | undefined;
|
|
1040
|
+
languageModel?: {
|
|
1041
|
+
provider: string;
|
|
1042
|
+
model: string;
|
|
1043
|
+
} | undefined;
|
|
1044
|
+
}>;
|
|
1045
|
+
export declare const sourceSchema: z.ZodObject<{
|
|
1046
|
+
type: z.ZodLiteral<"file">;
|
|
1047
|
+
repo: z.ZodString;
|
|
1048
|
+
path: z.ZodString;
|
|
1049
|
+
name: z.ZodString;
|
|
1050
|
+
language: z.ZodString;
|
|
1051
|
+
revision: z.ZodString;
|
|
1052
|
+
}, "strip", z.ZodTypeAny, {
|
|
1053
|
+
path: string;
|
|
1054
|
+
type: "file";
|
|
1055
|
+
name: string;
|
|
1056
|
+
language: string;
|
|
1057
|
+
repo: string;
|
|
1058
|
+
revision: string;
|
|
1059
|
+
}, {
|
|
1060
|
+
path: string;
|
|
1061
|
+
type: "file";
|
|
1062
|
+
name: string;
|
|
1063
|
+
language: string;
|
|
1064
|
+
repo: string;
|
|
1065
|
+
revision: string;
|
|
1066
|
+
}>;
|
|
1067
|
+
export declare const askCodebaseResponseSchema: z.ZodObject<{
|
|
1068
|
+
answer: z.ZodString;
|
|
1069
|
+
chatId: z.ZodString;
|
|
1070
|
+
chatUrl: z.ZodString;
|
|
1071
|
+
languageModel: z.ZodObject<{
|
|
1072
|
+
provider: z.ZodString;
|
|
1073
|
+
model: z.ZodString;
|
|
1074
|
+
displayName: z.ZodOptional<z.ZodString>;
|
|
1075
|
+
}, "strip", z.ZodTypeAny, {
|
|
1076
|
+
provider: string;
|
|
1077
|
+
model: string;
|
|
1078
|
+
displayName?: string | undefined;
|
|
1079
|
+
}, {
|
|
1080
|
+
provider: string;
|
|
1081
|
+
model: string;
|
|
1082
|
+
displayName?: string | undefined;
|
|
1083
|
+
}>;
|
|
1084
|
+
}, "strip", z.ZodTypeAny, {
|
|
1085
|
+
languageModel: {
|
|
1086
|
+
provider: string;
|
|
1087
|
+
model: string;
|
|
1088
|
+
displayName?: string | undefined;
|
|
1089
|
+
};
|
|
1090
|
+
answer: string;
|
|
1091
|
+
chatId: string;
|
|
1092
|
+
chatUrl: string;
|
|
1093
|
+
}, {
|
|
1094
|
+
languageModel: {
|
|
1095
|
+
provider: string;
|
|
1096
|
+
model: string;
|
|
1097
|
+
displayName?: string | undefined;
|
|
1098
|
+
};
|
|
1099
|
+
answer: string;
|
|
1100
|
+
chatId: string;
|
|
1101
|
+
chatUrl: string;
|
|
1102
|
+
}>;
|
package/dist/schemas.js
CHANGED
|
@@ -26,7 +26,6 @@ export const searchOptionsSchema = z.object({
|
|
|
26
26
|
});
|
|
27
27
|
export const searchRequestSchema = z.object({
|
|
28
28
|
query: z.string(), // The zoekt query to execute.
|
|
29
|
-
source: z.string().optional(), // The source of the search request.
|
|
30
29
|
...searchOptionsSchema.shape,
|
|
31
30
|
});
|
|
32
31
|
export const repositoryInfoSchema = z.object({
|
|
@@ -180,7 +179,6 @@ export const fileSourceResponseSchema = z.object({
|
|
|
180
179
|
repoCodeHostType: z.string(),
|
|
181
180
|
repoDisplayName: z.string().optional(),
|
|
182
181
|
repoExternalWebUrl: z.string().optional(),
|
|
183
|
-
branch: z.string().optional(),
|
|
184
182
|
webUrl: z.string(),
|
|
185
183
|
externalWebUrl: z.string().optional(),
|
|
186
184
|
});
|
|
@@ -238,4 +236,41 @@ export const listCommitsResponseSchema = z.array(z.object({
|
|
|
238
236
|
author_name: z.string(),
|
|
239
237
|
author_email: z.string(),
|
|
240
238
|
}));
|
|
239
|
+
export const languageModelInfoSchema = z.object({
|
|
240
|
+
provider: z.string().describe("The model provider (e.g., 'anthropic', 'openai')"),
|
|
241
|
+
model: z.string().describe("The model ID"),
|
|
242
|
+
displayName: z.string().optional().describe("Optional display name for the model"),
|
|
243
|
+
});
|
|
244
|
+
export const listLanguageModelsResponseSchema = z.array(languageModelInfoSchema);
|
|
245
|
+
export const askCodebaseRequestSchema = z.object({
|
|
246
|
+
query: z
|
|
247
|
+
.string()
|
|
248
|
+
.describe("The query to ask about the codebase."),
|
|
249
|
+
repos: z
|
|
250
|
+
.array(z.string())
|
|
251
|
+
.optional()
|
|
252
|
+
.describe("The repositories that are accessible to the agent during the chat. If not provided, all repositories are accessible."),
|
|
253
|
+
languageModel: languageModelInfoSchema
|
|
254
|
+
.omit({ displayName: true })
|
|
255
|
+
.optional()
|
|
256
|
+
.describe("The language model to use for answering the question. If not provided, defaults to the first model in the config. Use list_language_models to see available options."),
|
|
257
|
+
});
|
|
258
|
+
export const sourceSchema = z.object({
|
|
259
|
+
type: z.literal('file'),
|
|
260
|
+
repo: z.string(),
|
|
261
|
+
path: z.string(),
|
|
262
|
+
name: z.string(),
|
|
263
|
+
language: z.string(),
|
|
264
|
+
revision: z.string(),
|
|
265
|
+
});
|
|
266
|
+
export const askCodebaseResponseSchema = z.object({
|
|
267
|
+
answer: z.string().describe("The agent's final answer in markdown format"),
|
|
268
|
+
chatId: z.string().describe("ID of the persisted chat session"),
|
|
269
|
+
chatUrl: z.string().describe("URL to view the chat in the web UI"),
|
|
270
|
+
languageModel: z.object({
|
|
271
|
+
provider: z.string().describe("The model provider (e.g., 'anthropic', 'openai')"),
|
|
272
|
+
model: z.string().describe("The model ID"),
|
|
273
|
+
displayName: z.string().optional().describe("Optional display name for the model"),
|
|
274
|
+
}).describe("The language model used to generate the response"),
|
|
275
|
+
});
|
|
241
276
|
//# sourceMappingURL=schemas.js.map
|