File size: 1,383 Bytes
98c9143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
import { defineCommand } from "citty"
import { z } from "zod"

import { createMcpToolSearchSentinel } from "./lib/tool-search"

const SERVER_NAME = "tool_search"
const SERVER_VERSION = "1.0.0"

export const runMcpServer = async (): Promise<void> => {
  const server = new McpServer({
    name: SERVER_NAME,
    version: SERVER_VERSION,
  })

  server.registerTool(
    "search",
    {
      title: "Tool Search Bridge",
      description:
        "Load deferred tools by exact name through the Copilot API tool_search bridge.",
      inputSchema: {
        names: z
          .string()
          .describe(
            'Comma-separated exact deferred tool names to load, for example "TaskList,TaskGet,mcp__fetch__fetch".',
          ),
      },
      _meta: {
        "anthropic/alwaysLoad": true,
      },
    },
    ({ names }) => ({
      content: [
        {
          type: "text",
          text: createMcpToolSearchSentinel(names),
        },
      ],
    }),
  )

  await server.connect(new StdioServerTransport())
}

export const mcp = defineCommand({
  meta: {
    name: "mcp",
    description: "Start the Copilot API MCP tool_search bridge over stdio",
  },
  run() {
    return runMcpServer()
  },
})