csharp-mcp-server-sample

bluetsys/csharp-mcp-server-sample

3.2

If you are the rightful owner of csharp-mcp-server-sample and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

Csharp MCP Server Sample is a utility for fetching data from the JsonPlaceholder API, designed to work with .NET 6 and above.

Tools
1
Resources
0
Prompts
0

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게시글 데이터GetPostAsyncGetPostListAsync
/comments댓글 데이터GetCommentAsyncGetCommentListAsync
/albums앨범 데이터GetAlbumAsyncGetAlbumListAsync
/photos사진 데이터GetPhotoAsyncGetPhotoListAsync
/todos할 일(Todo) 데이터GetTodoAsyncGetTodoListAsync
/users사용자 데이터GetUserAsyncGetUserListAsync

사용 방법

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를 호출할 수 있습니다.

참고 자료 및 권장 사항

참고 자료

다른 언어로 작성하기

다른 언어로 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 파일을 참조하세요.