Skip to content

Commit 717b6de

Browse files
fix merge conflicts
1 parent ac4e694 commit 717b6de

1 file changed

Lines changed: 27 additions & 23 deletions

File tree

packages/web/src/features/mcp/server.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ import {
2323

2424
const dedent = _dedent.withOptions({ alignValues: true });
2525

26-
export function createMcpServer(): McpServer {
26+
export async function createMcpServer(): Promise<McpServer> {
2727
const server = new McpServer({
2828
name: 'sourcebot-mcp-server',
2929
version: SOURCEBOT_VERSION,
3030
});
3131

32+
const configuredLanguageModels = await getConfiguredLanguageModelsInfo();
33+
const hasLanguageModels = configuredLanguageModels.length > 0;
34+
3235
const toolContext: ToolContext = {
3336
source: 'sourcebot-mcp-server',
3437
}
@@ -56,10 +59,11 @@ export function createMcpServer(): McpServer {
5659
}
5760
);
5861

59-
server.registerTool(
60-
"ask_codebase",
61-
{
62-
description: dedent`
62+
if (hasLanguageModels) {
63+
server.registerTool(
64+
"ask_codebase",
65+
{
66+
description: dedent`
6367
DO NOT USE THIS TOOL UNLESS EXPLICITLY ASKED TO. THE PROMPT MUST SPECIFICALLY ASK TO USE THE ask_codebase TOOL.
6468
6569
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.
@@ -75,24 +79,24 @@ export function createMcpServer(): McpServer {
7579
7680
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.
7781
`,
78-
inputSchema: z.object({
79-
query: z.string().describe("The query to ask about the codebase."),
80-
repos: z.array(z.string()).optional().describe("The repositories accessible to the agent. If not provided, all repositories are accessible."),
81-
languageModel: languageModelInfoSchema.optional().describe("The language model to use. If not provided, defaults to the first model in the config."),
82-
visibility: z.enum(['PRIVATE', 'PUBLIC']).optional().describe("The visibility of the chat session. Defaults to PRIVATE for authenticated users."),
83-
}),
84-
annotations: {
85-
readOnlyHint: true,
86-
}
87-
},
88-
async (request) => {
89-
const result = await askCodebase({
90-
query: request.query,
91-
repos: request.repos,
92-
languageModel: request.languageModel,
93-
visibility: request.visibility as ChatVisibility | undefined,
94-
source: 'mcp',
95-
});
82+
inputSchema: z.object({
83+
query: z.string().describe("The query to ask about the codebase."),
84+
repos: z.array(z.string()).optional().describe("The repositories accessible to the agent. If not provided, all repositories are accessible."),
85+
languageModel: languageModelInfoSchema.optional().describe("The language model to use. If not provided, defaults to the first model in the config."),
86+
visibility: z.enum(['PRIVATE', 'PUBLIC']).optional().describe("The visibility of the chat session. Defaults to PRIVATE for authenticated users."),
87+
}),
88+
annotations: {
89+
readOnlyHint: true,
90+
}
91+
},
92+
async (request) => {
93+
const result = await askCodebase({
94+
query: request.query,
95+
repos: request.repos,
96+
languageModel: request.languageModel,
97+
visibility: request.visibility as ChatVisibility | undefined,
98+
source: 'mcp',
99+
});
96100

97101
if (isServiceError(result)) {
98102
return {

0 commit comments

Comments
 (0)