You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/McpServer/McpServer-CSharp/README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,8 +47,8 @@ Once configured, you can ask Copilot Chat for a random number, for example, `Giv
47
47
48
48
Once the MCP server package is published to NuGet.org, you can configure it in your preferred IDE. Both VS Code and Visual Studio use the `dnx` command to download and install the MCP server package from NuGet.org.
49
49
50
-
-**VS Code**: Create a `.vscode/mcp.json` file
51
-
-**Visual Studio**: Create a `<SOLUTIONDIR>\.mcp.json` file
50
+
-**VS Code**: Create a `<WORKSPACE DIRECTORY>/.vscode/mcp.json` file
51
+
-**Visual Studio**: Create a `<SOLUTION DIRECTORY>\.mcp.json` file
52
52
53
53
For both VS Code and Visual Studio, the configuration file uses the following server definition:
This README was created using the C# MCP server template project. It demonstrates how you can easily create an MCP server using C# and then package it in a NuGet package.
3
+
This README was created using the C# MCP server project template. It demonstrates how you can easily create an MCP server using C# and publish it as a NuGet package.
4
4
5
5
See [aka.ms/nuget/mcp/guide](https://aka.ms/nuget/mcp/guide) for the full guide.
6
6
@@ -14,67 +14,70 @@ See [aka.ms/nuget/mcp/guide](https://aka.ms/nuget/mcp/guide) for the full guide.
14
14
15
15
The `bin/Release` directory will contain the package file (.nupkg), which can be [published to NuGet.org](https://learn.microsoft.com/nuget/nuget-org/publish-a-package).
16
16
17
-
## Using the MCP Server in VS Code
17
+
## Developing locally
18
18
19
-
Once the MCP server package is published to NuGet.org, you can use the following VS Code user configuration to download and install the MCP server package. See [Use MCP servers in VS Code (Preview)](https://code.visualstudio.com/docs/copilot/chat/mcp-servers) for more information about using MCP servers in VS Code.
19
+
To test this MCP server from source code (locally) without using a built MCP server package, you can configure your IDE to run the project directly using `dotnet run`.
20
20
21
21
```json
22
22
{
23
-
"mcp": {
24
-
"servers": {
25
-
"mcpserver": {
26
-
"type": "stdio",
27
-
"command": "dnx",
28
-
"args": [
29
-
"<your package ID here>",
30
-
"--version",
31
-
"<your package version here>",
32
-
"--yes"
33
-
]
34
-
}
23
+
"servers": {
24
+
"McpServer-CSharp": {
25
+
"type": "stdio",
26
+
"command": "dotnet",
27
+
"args": [
28
+
"run",
29
+
"--project",
30
+
"<PATH TO PROJECT DIRECTORY>"
31
+
]
35
32
}
36
33
}
37
34
}
38
35
```
39
36
40
-
Now you can ask Copilot Chat for a random number, for example, `Give me 3 random numbers`. It should prompt you to use the `get_random_number` tool on the `mcpserver` MCP server and show you the results.
37
+
## Testing the MCP Server
38
+
39
+
Once configured, you can ask Copilot Chat for a random number, for example, `Give me 3 random numbers`. It should prompt you to use the `get_random_number` tool on the `McpServer-CSharp` MCP server and show you the results.
40
+
41
+
## Publishing to NuGet.org
42
+
43
+
1. Run `dotnet pack -c Release` to create the NuGet package
44
+
2. Publish to NuGet.org with `dotnet nuget push bin/Release/*.nupkg --api-key <your-api-key> --source https://api.nuget.org/v3/index.json`
45
+
46
+
## Using the MCP Server from NuGet.org
47
+
48
+
Once the MCP server package is published to NuGet.org, you can configure it in your preferred IDE. Both VS Code and Visual Studio use the `dnx` command to download and install the MCP server package from NuGet.org.
41
49
42
-
## Developing locally in VS Code
50
+
-**VS Code**: Create a `<WORKSPACE DIRECTORY>/.vscode/mcp.json` file
51
+
-**Visual Studio**: Create a `<SOLUTION DIRECTORY>\.mcp.json` file
43
52
44
-
To test this MCP server from source code (locally) without using a built MCP server package, create a `.vscode/mcp.json`file (a VS Code workspace settings file) in your project directory and add the following configuration:
53
+
For both VS Code and Visual Studio, the configuration file uses the following server definition:
45
54
46
55
```json
47
56
{
48
57
"servers": {
49
-
"mcpserver": {
58
+
"McpServer-CSharp": {
50
59
"type": "stdio",
51
-
"command": "dotnet",
60
+
"command": "dnx",
52
61
"args": [
53
-
"run",
54
-
"--project",
55
-
"<RELATIVE PATH TO PROJECT DIRECTORY>"
62
+
"<your package ID here>",
63
+
"--version",
64
+
"<your package version here>",
65
+
"--yes"
56
66
]
57
67
}
58
68
}
59
69
}
60
70
```
61
71
62
-
Alternatively, you can configure your VS Code user settings to use your local project:
72
+
## More information
63
73
64
-
```json
65
-
{
66
-
"mcp": {
67
-
"servers": {
68
-
"mcpserver": {
69
-
"type": "stdio",
70
-
"command": "dotnet",
71
-
"args": [
72
-
"run",
73
-
"--project",
74
-
"<FULL PATH TO PROJECT DIRECTORY>"
75
-
]
76
-
}
77
-
}
78
-
}
79
-
}
80
-
```
74
+
.NET MCP servers use the [ModelContextProtocol](https://www.nuget.org/packages/ModelContextProtocol) C# SDK. For more information about MCP:
0 commit comments