Skip to main content

Using MCP servers with the Copilot SDK

Integrate MCP servers with the Второй пилот SDK to extend your application's capabilities with external tools.

Кто может использовать эту функцию?

GitHub Copilot SDK Доступна со всеми Copilot тарифными планами.

Примечание.

Второй пилот SDK is currently in Technical Preview. Functionality and availability are subject to change.

The Второй пилот SDK can integrate with MCP servers (Model Context Protocol) to extend the assistant's capabilities with external tools. MCP servers run as separate processes and expose tools (functions) that Copilot can invoke during conversations.

What is MCP?

Model Context Protocol (MCP) is an open standard for connecting AI assistants to external tools and data sources. MCP servers can execute code or scripts, query databases, access file systems, call external APIs, and more.

Server types

The SDK supports two types of MCP servers:

TypeDescriptionUse case
Local/StdioRuns as a subprocess, communicates via stdin/stdoutLocal tools, file access, custom scripts
HTTP/SSERemote server accessed via HTTPShared services, cloud-hosted tools

Configuration

import { CopilotClient } from "@github/copilot-sdk";

const client = new CopilotClient();
const session = await client.createSession({
    model: "gpt-5",
    mcpServers: {
        // Local MCP server (stdio)
        "my-local-server": {
            type: "local",
            command: "node",
            args: ["./mcp-server.js"],
            env: { DEBUG: "true" },
            cwd: "./servers",
            tools: ["*"],  // "*" = all tools, [] = none, or list specific tools
            timeout: 30000,
        },
        // Remote MCP server (HTTP)
        "github": {
            type: "http",
            url: "https://api.githubcopilot.com/mcp/",
            headers: { "Authorization": "Bearer ${TOKEN}" },
            tools: ["*"],
        },
    },
});

For examples in Python, Go, and .NET, see the github/copilot-sdk repository.

Quick start: filesystem MCP server

Here's a complete working example using the official @modelcontextprotocol/server-filesystem MCP server:

import { CopilotClient } from "@github/copilot-sdk";

async function main() {
    const client = new CopilotClient();

    // Create session with filesystem MCP server
    const session = await client.createSession({
        mcpServers: {
            filesystem: {
                type: "local",
                command: "npx",
                args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
                tools: ["*"],
            },
        },
    });

    console.log("Session created:", session.sessionId);

    // The model can now use filesystem tools
    const result = await session.sendAndWait({
        prompt: "List the files in the allowed directory",
    });

    console.log("Response:", result?.data?.content);

    await session.disconnect();
    await client.stop();
}

main();

Совет

You can use any MCP server from the MCP Servers Directory. Popular options include @modelcontextprotocol/server-github, @modelcontextprotocol/server-sqlite, and @modelcontextprotocol/server-puppeteer.

Configuration options

Local/Stdio server

PropertyTypeRequiredDescription
type"local" or "stdio"NoServer type (defaults to local)
commandstringYesCommand to execute
argsstring[]YesCommand arguments
envobjectNoEnvironment variables
cwdstringNoWorking directory
toolsstring[]NoTools to enable (["*"] for all, [] for none)
timeoutnumberNoTimeout in milliseconds

Remote server (HTTP/SSE)

PropertyTypeRequiredDescription
type"http" or "sse"YesServer type
urlstringYesServer URL
headersobjectNoHTTP headers (for example, for auth)
toolsstring[]NoTools to enable
timeoutnumberNoTimeout in milliseconds

Troubleshooting

Tools not showing up or not being invoked

  1. Verify the MCP server starts correctly—Check that the command and arguments are correct, and ensure the server process doesn't crash on startup. Look for error output in stderr.
  2. Check tool configuration—Make sure tools is set to ["*"] or lists the specific tools you need. An empty array [] means no tools are enabled.
  3. Verify connectivity for remote servers—Ensure the URL is accessible and check that authentication headers are correct.

Common issues

IssueSolution
"MCP server not found"Verify the command path is correct and executable
"Connection refused" (HTTP)Check the URL and ensure the server is running
"Timeout" errorsIncrease the timeout value or check server performance
Tools work but aren't calledEnsure your prompt clearly requires the tool's functionality

Further reading