Skip to content

Commit 34c4b85

Browse files
authored
Merge branch 'modelcontextprotocol:main' into feature/elicitation
2 parents 5e74ecb + 9b15ff9 commit 34c4b85

30 files changed

+7011
-56
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111

1212
steps:
1313
- uses: actions/checkout@v4
14-
- uses: actions/setup-node@v2
14+
- uses: actions/setup-node@v4
1515
with:
1616
node-version: 20
1717
cache: npm

docs/clients.mdx

Lines changed: 197 additions & 0 deletions
Large diffs are not rendered by default.

docs/docs.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,55 @@
177177
}
178178
]
179179
},
180+
{
181+
"group": "draft",
182+
"pages": [
183+
"specification/draft/index",
184+
"specification/draft/changelog",
185+
"specification/draft/architecture/index",
186+
{
187+
"group": "Base Protocol",
188+
"pages": [
189+
"specification/draft/basic/index",
190+
"specification/draft/basic/lifecycle",
191+
"specification/draft/basic/transports",
192+
"specification/draft/basic/authorization",
193+
{
194+
"group": "Utilities",
195+
"pages": [
196+
"specification/draft/basic/utilities/cancellation",
197+
"specification/draft/basic/utilities/ping",
198+
"specification/draft/basic/utilities/progress"
199+
]
200+
}
201+
]
202+
},
203+
{
204+
"group": "Client Features",
205+
"pages": [
206+
"specification/draft/client/roots",
207+
"specification/draft/client/sampling"
208+
]
209+
},
210+
{
211+
"group": "Server Features",
212+
"pages": [
213+
"specification/draft/server/index",
214+
"specification/draft/server/prompts",
215+
"specification/draft/server/resources",
216+
"specification/draft/server/tools",
217+
{
218+
"group": "Utilities",
219+
"pages": [
220+
"specification/draft/server/utilities/completion",
221+
"specification/draft/server/utilities/logging",
222+
"specification/draft/server/utilities/pagination"
223+
]
224+
}
225+
]
226+
}
227+
]
228+
},
180229
{
181230
"group": "Resources",
182231
"pages": [

docs/examples.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ These MCP servers are maintained by companies for their platforms:
4646
- **[E2B](https://github.com/e2b-dev/mcp-server)** - Execute code in secure cloud sandboxes
4747
- **[Neon](https://github.com/neondatabase/mcp-server-neon)** - Interact with the Neon serverless Postgres platform
4848
- **[Obsidian Markdown Notes](https://github.com/calclavia/mcp-obsidian)** - Read and search through Markdown notes in Obsidian vaults
49+
- **[Prisma](https://pris.ly/docs/mcp-server)** - Manage and interact with Prisma Postgres databases
4950
- **[Qdrant](https://github.com/qdrant/mcp-server-qdrant/)** - Implement semantic memory using the Qdrant vector search engine
5051
- **[Raygun](https://github.com/MindscapeHQ/mcp-server-raygun)** - Access crash reporting and monitoring data
5152
- **[Search1API](https://github.com/fatwang2/search1api-mcp)** - Unified API for search, crawling, and sitemaps
@@ -121,6 +122,7 @@ To use an MCP server with Claude, add it to your configuration:
121122
- [Awesome MCP Servers](https://github.com/punkpeye/awesome-mcp-servers) - Curated list of MCP servers
122123
- [MCP CLI](https://github.com/wong2/mcp-cli) - Command-line inspector for testing MCP servers
123124
- [MCP Get](https://mcp-get.com) - Tool for installing and managing MCP servers
125+
- [Pipedream MCP](https://mcp.pipedream.com) - MCP servers with built-in auth for 3,000+ APIs and 10,000+ tools
124126
- [Supergateway](https://github.com/supercorp-ai/supergateway) - Run MCP stdio servers over SSE
125127
- [Zapier MCP](https://zapier.com/mcp) - MCP Server with over 7,000+ apps and 30,000+ actions
126128

docs/quickstart/client.mdx

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ source .venv/bin/activate
3939
uv add mcp anthropic python-dotenv
4040

4141
# Remove boilerplate files
42+
# On Windows:
43+
del main.py
44+
# On Unix or MacOS:
4245
rm main.py
4346

4447
# Create our main file
@@ -560,13 +563,13 @@ async connectToServer(serverScriptPath: string) {
560563
? "python"
561564
: "python3"
562565
: process.execPath;
563-
566+
564567
this.transport = new StdioClientTransport({
565568
command,
566569
args: [serverScriptPath],
567570
});
568571
this.mcp.connect(this.transport);
569-
572+
570573
const toolsResult = await this.mcp.listTools();
571574
this.tools = toolsResult.tools.map((tool) => {
572575
return {
@@ -1370,7 +1373,7 @@ If you see:
13701373
</Tab>
13711374

13721375
<Tab title="C#">
1373-
[You can find the complete code for this tutorial here.](https://github.io/modelcontextprotocol/csharp-sdk/tree/main/samples/QuickstartClient)
1376+
[You can find the complete code for this tutorial here.](https://github.com/modelcontextprotocol/csharp-sdk/tree/main/samples/QuickstartClient)
13741377

13751378
## System Requirements
13761379
Before starting, ensure your system meets these requirements:
@@ -1403,14 +1406,19 @@ dotnet user-secrets set "ANTHROPIC_API_KEY" "<your key here>"
14031406

14041407
## Creating the Client
14051408
### Basic Client Structure
1406-
First, let's setup the basic client class:
1409+
First, let's setup the basic client class in the file `Program.cs`:
14071410
```csharp
1411+
using Anthropic.SDK;
1412+
using Microsoft.Extensions.AI;
14081413
using Microsoft.Extensions.Configuration;
14091414
using Microsoft.Extensions.Hosting;
1415+
using ModelContextProtocol.Client;
1416+
using ModelContextProtocol.Protocol.Transport;
14101417
1411-
var builder = Host.CreateEmptyApplicationBuilder(settings: null);
1418+
var builder = Host.CreateApplicationBuilder(args);
14121419
14131420
builder.Configuration
1421+
.AddEnvironmentVariables()
14141422
.AddUserSecrets<Program>();
14151423
```
14161424

@@ -1419,47 +1427,46 @@ This creates the beginnings of a .NET console application that can read the API
14191427
Next, we'll setup the MCP Client:
14201428

14211429
```csharp
1422-
var (command, arguments) = args switch
1423-
{
1424-
[var script] when script.EndsWith(".py") => ("python", script),
1425-
[var script] when script.EndsWith(".js") => ("node", script),
1426-
[var script] when Directory.Exists(script) || (File.Exists(script) && script.EndsWith(".csproj")) => ("dotnet", $"run --project {script} --no-build"),
1427-
_ => throw new NotSupportedException("An unsupported server script was provided. Supported scripts are .py, .js, or .csproj")
1428-
};
1430+
var (command, arguments) = GetCommandAndArguments(args);
14291431
1430-
await using var mcpClient = await McpClientFactory.CreateAsync(new()
1432+
var clientTransport = new StdioClientTransport(new()
14311433
{
1432-
Id = "demo-server",
14331434
Name = "Demo Server",
1434-
TransportType = TransportTypes.StdIo,
1435-
TransportOptions = new()
1436-
{
1437-
["command"] = command,
1438-
["arguments"] = arguments,
1439-
}
1435+
Command = command,
1436+
Arguments = arguments,
14401437
});
14411438
1439+
await using var mcpClient = await McpClientFactory.CreateAsync(clientTransport);
1440+
14421441
var tools = await mcpClient.ListToolsAsync();
14431442
foreach (var tool in tools)
14441443
{
14451444
Console.WriteLine($"Connected to server with tools: {tool.Name}");
14461445
}
14471446
```
1448-
<Note>
1449-
Be sure to add the `using` statements for the namespaces:
1447+
1448+
Add this function at the end of the `Program.cs` file:
1449+
14501450
```csharp
1451-
using ModelContextProtocol.Client;
1452-
using ModelContextProtocol.Protocol.Transport;
1451+
static (string command, string[] arguments) GetCommandAndArguments(string[] args)
1452+
{
1453+
return args switch
1454+
{
1455+
[var script] when script.EndsWith(".py") => ("python", args),
1456+
[var script] when script.EndsWith(".js") => ("node", args),
1457+
[var script] when Directory.Exists(script) || (File.Exists(script) && script.EndsWith(".csproj")) => ("dotnet", ["run", "--project", script, "--no-build"]),
1458+
_ => throw new NotSupportedException("An unsupported server script was provided. Supported scripts are .py, .js, or .csproj")
1459+
};
1460+
}
14531461
```
1454-
</Note>
14551462

1456-
This configures a MCP client that will connect to a server that is provided as a command line argument. It then lists the available tools from the connected server.
1463+
This creates a MCP client that will connect to a server that is provided as a command line argument. It then lists the available tools from the connected server.
14571464

14581465
### Query processing logic
14591466
Now let's add the core functionality for processing queries and handling tool calls:
14601467

14611468
```csharp
1462-
using IChatClient anthropicClient = new AnthropicClient(new APIAuthentication(builder.Configuration["ANTHROPIC_API_KEY"]))
1469+
using var anthropicClient = new AnthropicClient(new APIAuthentication(builder.Configuration["ANTHROPIC_API_KEY"]))
14631470
.Messages
14641471
.AsBuilder()
14651472
.UseFunctionInvocation()
@@ -1472,29 +1479,34 @@ var options = new ChatOptions
14721479
Tools = [.. tools]
14731480
};
14741481
1475-
while (true)
1476-
{
1477-
Console.WriteLine("MCP Client Started!");
1478-
Console.WriteLine("Type your queries or 'quit' to exit.");
1479-
1480-
string? query = Console.ReadLine();
1482+
Console.ForegroundColor = ConsoleColor.Green;
1483+
Console.WriteLine("MCP Client Started!");
1484+
Console.ResetColor();
14811485
1486+
PromptForInput();
1487+
while(Console.ReadLine() is string query && !"exit".Equals(query, StringComparison.OrdinalIgnoreCase))
1488+
{
14821489
if (string.IsNullOrWhiteSpace(query))
14831490
{
1491+
PromptForInput();
14841492
continue;
14851493
}
1486-
if (string.Equals(query, "quit", StringComparison.OrdinalIgnoreCase))
1487-
{
1488-
break;
1489-
}
1490-
1491-
var response = anthropicClient.GetStreamingResponseAsync(query, options);
14921494
1493-
await foreach (var message in response)
1495+
await foreach (var message in anthropicClient.GetStreamingResponseAsync(query, options))
14941496
{
1495-
Console.Write(message.Text);
1497+
Console.Write(message);
14961498
}
14971499
Console.WriteLine();
1500+
1501+
PromptForInput();
1502+
}
1503+
1504+
static void PromptForInput()
1505+
{
1506+
Console.WriteLine("Enter a command (or 'exit' to quit):");
1507+
Console.ForegroundColor = ConsoleColor.Cyan;
1508+
Console.Write("> ");
1509+
Console.ResetColor();
14981510
}
14991511
```
15001512

@@ -1516,7 +1528,8 @@ while (true)
15161528
* The server processes the query and returns a response.
15171529
* The response is displayed to the user.
15181530

1519-
### Running the Client
1531+
## Running the Client
1532+
15201533
To run your client with any MCP server:
15211534
```bash
15221535
dotnet run -- path/to/server.csproj # dotnet server

0 commit comments

Comments
 (0)