-
Notifications
You must be signed in to change notification settings - Fork 1.3k
docs: add MCP server usage documentation #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,225 @@ | ||||||
| # Using MCP Servers with the GitHub Copilot SDK | ||||||
|
|
||||||
| The Copilot 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. | ||||||
|
|
||||||
| > **Note:** This is an evolving feature. See [issue #36](https://github.com/github/copilot-sdk/issues/36) for ongoing discussion. | ||||||
|
|
||||||
| ## What is MCP? | ||||||
|
|
||||||
| [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) 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 much more | ||||||
|
|
||||||
| ## Server Types | ||||||
|
|
||||||
| The SDK supports two types of MCP servers: | ||||||
|
|
||||||
| | Type | Description | Use Case | | ||||||
| |------|-------------|----------| | ||||||
| | **Local/Stdio** | Runs as a subprocess, communicates via stdin/stdout | Local tools, file access, custom scripts | | ||||||
| | **HTTP/SSE** | Remote server accessed via HTTP | Shared services, cloud-hosted tools | | ||||||
|
|
||||||
| ## Configuration | ||||||
|
|
||||||
| ### Node.js / TypeScript | ||||||
|
|
||||||
| ```typescript | ||||||
| import { CopilotClient } from "@github/copilot-sdk"; | ||||||
|
|
||||||
| const client = new CopilotClient(); | ||||||
| const session = await client.createSession({ | ||||||
| model: "gpt-4.1", | ||||||
| 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: ["*"], | ||||||
| }, | ||||||
| }, | ||||||
| }); | ||||||
| ``` | ||||||
|
|
||||||
| ### Python | ||||||
|
|
||||||
| ```python | ||||||
| import asyncio | ||||||
| from copilot import CopilotClient | ||||||
|
|
||||||
| async def main(): | ||||||
| client = CopilotClient() | ||||||
| await client.start() | ||||||
|
|
||||||
| session = await client.create_session({ | ||||||
| "model": "gpt-4.1", | ||||||
|
||||||
| "mcp_servers": { | ||||||
| # Local MCP server (stdio) | ||||||
| "my-local-server": { | ||||||
| "type": "local", | ||||||
| "command": "python", | ||||||
| "args": ["./mcp_server.py"], | ||||||
| "env": {"DEBUG": "true"}, | ||||||
| "cwd": "./servers", | ||||||
| "tools": ["*"], | ||||||
| "timeout": 30000, | ||||||
| }, | ||||||
| # Remote MCP server (HTTP) | ||||||
| "github": { | ||||||
| "type": "http", | ||||||
| "url": "https://api.githubcopilot.com/mcp/", | ||||||
| "headers": {"Authorization": "Bearer ${TOKEN}"}, | ||||||
| "tools": ["*"], | ||||||
| }, | ||||||
| }, | ||||||
| }) | ||||||
|
|
||||||
| response = await session.send_and_wait({ | ||||||
| "prompt": "List my recent GitHub notifications" | ||||||
| }) | ||||||
| print(response.data.content) | ||||||
|
|
||||||
| await client.stop() | ||||||
|
|
||||||
| asyncio.run(main()) | ||||||
| ``` | ||||||
|
|
||||||
| ### Go | ||||||
|
|
||||||
| ```go | ||||||
| package main | ||||||
|
|
||||||
| import ( | ||||||
| "log" | ||||||
| copilot "github.com/github/copilot-sdk/go" | ||||||
| ) | ||||||
|
|
||||||
| func main() { | ||||||
| client := copilot.NewClient(nil) | ||||||
| if err := client.Start(); err != nil { | ||||||
| log.Fatal(err) | ||||||
| } | ||||||
| defer client.Stop() | ||||||
|
|
||||||
| session, err := client.CreateSession(&copilot.SessionConfig{ | ||||||
| Model: "gpt-4.1", | ||||||
|
||||||
| MCPServers: map[string]copilot.MCPServerConfig{ | ||||||
| "my-local-server": { | ||||||
| Type: "local", | ||||||
| Command: "node", | ||||||
| Args: []string{"./mcp-server.js"}, | ||||||
| Tools: []string{"*"}, | ||||||
| }, | ||||||
| }, | ||||||
| }) | ||||||
| if err != nil { | ||||||
| log.Fatal(err) | ||||||
| } | ||||||
|
|
||||||
| // Use the session... | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ### .NET | ||||||
|
|
||||||
| ```csharp | ||||||
| using GitHub.Copilot.SDK; | ||||||
|
|
||||||
| await using var client = new CopilotClient(); | ||||||
| await using var session = await client.CreateSessionAsync(new SessionConfig | ||||||
| { | ||||||
| Model = "gpt-4.1", | ||||||
|
||||||
| McpServers = new Dictionary<string, McpServerConfig> | ||||||
|
||||||
| McpServers = new Dictionary<string, McpServerConfig> | |
| McpServers = new Dictionary<string, object> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The model value "gpt-4.1" is inconsistent with the rest of the codebase and may not be valid. According to the Python SDK types in
python/copilot/types.pyline 200, valid models are: "gpt-5", "claude-sonnet-4", "claude-sonnet-4.5", "claude-haiku-4.5". The rest of the documentation and examples in this repository use "gpt-5". Consider changing this to "gpt-5" to maintain consistency.