Csharp MCP Server Sample
csharp-mcp-server-sample
Ask AI about Csharp MCP Server Sample
Powered by Claude ยท Grounded in docs
I know everything about Csharp MCP Server Sample. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Csharp MCP Server Sample
๊ฐ์
Csharp MCP Server Sample๋ JsonPlaceholder(https://jsonplaceholder.typicode.com/) API๋ฅผ ํธ์ถํ์ฌ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋ ์ ํธ๋ฆฌํฐ๋ฅผ ์ ๊ณตํฉ๋๋ค. ์ด ํ๋ก์ ํธ๋ .NET 6 ์ด์์์ ๋์ํ๋ฉฐ, ์ฝ์ ์ ํ๋ฆฌ์ผ์ด์
๋๋ ASP.NET Core ํ๋ก์ ํธ์์ ์ฝ๊ฒ ํตํฉํ์ฌ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๊ถ์ฅ ์ฌํญ
- .NET 10.0 SDK
- Visual Studio Code
- Visual Studio Code์ฉ GitHub Copilot ํ์ฅ
.NET 10.0 SDK ์ค์น๋ ์ฌ๊ธฐ๋ฅผ ์ฐธ๊ณ ํ์ธ์.
์ฃผ์ ๊ธฐ๋ฅ
- JsonPlaceholder API ํธ์ถ์ ์ํ HttpClient ์์ฑ ๋ฐ ๊ด๋ฆฌ
- ๋ค์ํ ์๋ํฌ์ธํธ(
/posts,/comments,/albums,/photos,/todos,/users)์ ๋ํ ๋ฐ์ดํฐ ์กฐํ ๊ธฐ๋ฅ ์ ๊ณต - ๋จ๊ฑด ์กฐํ ๋ฐ ๋ชฉ๋ก ์กฐํ ์ง์
์ง์ ์๋ํฌ์ธํธ
| ์๋ํฌ์ธํธ | ์ค๋ช | ๋จ๊ฑด ์กฐํ ๋ฉ์๋ | ๋ชฉ๋ก ์กฐํ ๋ฉ์๋ |
|---|---|---|---|
/posts | ๊ฒ์๊ธ ๋ฐ์ดํฐ | GetPostAsync | GetPostListAsync |
/comments | ๋๊ธ ๋ฐ์ดํฐ | GetCommentAsync | GetCommentListAsync |
/albums | ์จ๋ฒ ๋ฐ์ดํฐ | GetAlbumAsync | GetAlbumListAsync |
/photos | ์ฌ์ง ๋ฐ์ดํฐ | GetPhotoAsync | GetPhotoListAsync |
/todos | ํ ์ผ(Todo) ๋ฐ์ดํฐ | GetTodoAsync | GetTodoListAsync |
/users | ์ฌ์ฉ์ ๋ฐ์ดํฐ | GetUserAsync | GetUserListAsync |
์ฌ์ฉ ๋ฐฉ๋ฒ
1. HttpClient ์์ฑ
CreateJsonPlaceholderClient ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ JsonPlaceholder ์ ์ฉ HttpClient๋ฅผ ์์ฑํฉ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก BaseAddress๋ JsonPlaceholder API๋ก ์ค์ ๋๋ฉฐ, ๊ณตํต ํค๋๊ฐ ์ ์ฉ๋ฉ๋๋ค.
private HttpClient CreateJsonPlaceholderClient(
TimeSpan? timeout = null,
string? userAgent = "JsonPlaceholderSample/1.0",
string? bearerToken = null,
SocketsHttpHandler? handler = null)
2. ๋จ๊ฑด ์กฐํ
ํน์ ID์ ํด๋นํ๋ ๋ฐ์ดํฐ๋ฅผ ์กฐํํ๋ ค๋ฉด ์๋ ๋ฉ์๋๋ฅผ ์ฌ์ฉํฉ๋๋ค.
์: GetPostAsync
[McpServerTool]
[Description("Post ๋จ๊ฑด ์กฐํ (JSON ๋ฐํ)")]
public async Task<string> GetPostAsync(int id)
3. ๋ชฉ๋ก ์กฐํ
์ ์ฒด ๋ฐ์ดํฐ๋ฅผ ์กฐํํ๋ ค๋ฉด ์๋ ๋ฉ์๋๋ฅผ ์ฌ์ฉํฉ๋๋ค.
์: GetPostListAsync
[McpServerTool]
[Description("Post ๋ชฉ๋ก ์กฐํ (JSON ๋ฐํ)")]
public async Task<string> GetPostListAsync()
์ค์น ๋ฐ ์คํ
1. ํ๋ก์ ํธ ๋น๋
pwsh
> dotnet build
2. ์คํ
Program.cs์์ MCP ์๋ฒ๋ฅผ ์คํํฉ๋๋ค.
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddConsole(o => o.LogToStandardErrorThreshold = LogLevel.Trace);
builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithTools<SampleTools>();
await builder.Build().RunAsync();
3. MCP ๋๊ตฌ ์ฌ์ฉ
SampleTools ํด๋์ค์ ์ ์๋ MCP ๋๊ตฌ๋ฅผ ํตํด JsonPlaceholder API๋ฅผ ํธ์ถํ ์ ์์ต๋๋ค.
์ฐธ๊ณ ์๋ฃ ๋ฐ ๊ถ์ฅ ์ฌํญ
์ฐธ๊ณ ์๋ฃ
- ์์ธํ ์ฌํญ์ Model Context Protocol ๊ณต์ ์ฌ์ดํธ๋ฅผ ์ฐธ๊ณ ํ์ธ์.
- ๋ณธ ์์ค์ฝ๋๋ Microsoft ๊ณต์ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ฌ ์์ฑ๋์์ต๋๋ค.
- ์ ๋ฌธ์์ ๋ด์ฉ์ GitHub ์ ์ฅ์์ ํด๋นํ๋ MS ๊ณต์ ๋ฌธ์์ ๋๋ค.
๋ค๋ฅธ ์ธ์ด๋ก ์์ฑํ๊ธฐ
๋ค๋ฅธ ์ธ์ด๋ก MCP ์๋ฒ๋ฅผ ์์ฑํ๋ ค๋ฉด ์๋ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ธ์:
- SDK ๋ฌธ์
- ์ฌ์ ๋ฌธ์
- ๊ฐ์ธ์ ์๊ฒฌ C#์ด 10๋ถ ์ด๋ด๋ก ํ ์คํธ ๊ฐ๋ฅ ๊ฐ์ฅ ๋๋ฆฐ๊ฑด python ๋ฒ์ ผ์ถฉ๋ ๋ฑ์ผ๋ก ์ฝ 1์๊ฐ ์ ๋ ๊ฑธ๋ฆผ
.vscode/mcp.json ํ์ผ ์ค๋ช
์ ์ฒด
- Public-Data-Search: PHP HTTP๋ก ์์ฑ๋ ๊ณต๊ณต๋ฐ์ดํฐ ๊ฒ์ ์์ (์์ค ์ฝ๋๋ ๋ฏธ๊ณต๊ฐ)
- Sample-McpServer: ๋ณธ ์ํ ํ์ผ์ MCP ์ค์ (์์ค ์ฝ๋ ์ฐธ๊ณ )
๊ธฐ๋ฅ
- ์์: ํด๋น MCP๋ฅผ ์คํ ํ๋ค.
- ์คํ์ค: ํด๋น MCP์ ๋ก๊ทธ๋ฅผ ๋ณธ๋ค.( ์ค๋ฅ ๋ก๊ทธ๋ฑ์ ํ์ ํ ์ ์๋ค)
- ์ค์ง: ํด๋น MCP๋ฅผ ์ค์ง ํ๋ค.
- ๋ค์์์: ํด๋น MCP๋ฅผ ๋ค์ ์์ํ๋ค. ( ์ฝ๋ ์์ ํ ์๋ก ์ ์ฉ ํ๊ธฐ ์ํด ์ฌ์ฉ )
์์ธํ ์ฌํญ์ Visual Studio Code MCP ์๋ฒ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ธ์.
๊ฒฐ๋ก
- MCP Server๋ฅผ ๋ฑ๋ก ํ ์ ์๋ agent๋ LLM ์๋น์ค๋ฑ์์ ๋ค์ํ๊ฒ MCP ๋ฅผ ์์ฑ ํด์ ํ์ ํ์ธ์ฌ
๋ผ์ด์ ์ค
์ด ํ๋ก์ ํธ๋ ์คํ์์ค ๋ผ์ด์ ์ค๋ฅผ ๋ฐ๋ฆ ๋๋ค. ์์ธํ ๋ด์ฉ์ LICENSE ํ์ผ์ ์ฐธ์กฐํ์ธ์.
