위의 글을 보고, 표준 입/출력으로 MCP 서버를 간단히 만들어볼 수 있겠다는 것을 파악하여 곧바로 프로토타이핑해보았는데 잘 작동합니다. 표준 입출력 인터페이스만 제공하면 되는 것이니 조건만 맞으면 유연하게 쓸 수 있는 셈입니다.
<Query Kind="Statements">
<NuGetReference>Microsoft.Extensions.Hosting</NuGetReference>
<NuGetReference Prerelease="true">ModelContextProtocol</NuGetReference>
<Namespace>Microsoft.Extensions.DependencyInjection</Namespace>
<Namespace>Microsoft.Extensions.Hosting</Namespace>
<Namespace>ModelContextProtocol.Server</Namespace>
<Namespace>System.ComponentModel</Namespace>
</Query>
var builder = Host.CreateEmptyApplicationBuilder(settings: null);
builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithToolsFromAssembly();
await builder.Build().RunAsync();
[McpServerToolType]
public static class EchoTool
{
[McpServerTool, Description("Echoes the message back to the client.")]
public static string Echo(string message) => $"Hello from C#: {message}";
[McpServerTool, Description("Echoes in reverse the message sent by the client.")]
public static string ReverseEcho(string message) => new string(message.Reverse().ToArray());
}
위와 같이 MCP 서버 코드를 만든 후, 적용하려는 VSCode 작업 폴더에 .vscode/mcp.json
파일을 다음과 같이 만듭니다. 제 경우에는 LINQPad 스크립트 경로를 다음과 같이 지정했습니다.
{
"inputs": [],
"servers": {
"MyFirstMCP": {
"type": "stdio",
"command": "C:\\Program Files\\LINQPad8\\LPRun8.exe",
"args": [
"D:\\Users\\rkttu\\Documents\\LINQPad Queries\\mcp-test.linq"
]
}
}
}
그리고 VS Code Insider 버전에서 에이전트 모드로 Copilot을 연 다음, 도구 버튼을 눌렀을 때 다음과 같이 명령어 asset들이 인식되어 나타나면 정상적으로 실행되고 있는 것입니다.
같은 기능을 만들기 위해서 Web API를 만들어야 했던 이전 GPTs보다 훨씬 개발자 친화적이고 유연성 있는 인터페이스여서 재미있는 경험이었습니다.
덧. 조만간 LINQPad macOS 버전으로도 LPRUN 명령줄 유틸리티가 추가될 예정이니 macOS에서도 C#으로 스크립트 언어처럼 LINQPad의 강력한 기능을 활용해서 MCP 서버를 만들 수 있게 됩니다.