⚠️ ਮਹੱਤਵਪੂਰਨ ਅੱਪਡੇਟ: ਐਮਸੀਪੀ ਸਪੈਸਿਫਿਕੇਸ਼ਨ 2025-06-18 ਦੇ ਤਹਿਤ, ਅਲੱਗ SSE (ਸਰਵਰ-ਸੈਂਟ ਇਵੈਂਟਸ) ਟ੍ਰਾਂਸਪੋਰਟ ਨੂੰ ਡਿਪ੍ਰੀਕੇਟ ਕਰ ਦਿੱਤਾ ਗਿਆ ਹੈ ਅਤੇ "Streamable HTTP" ਟ੍ਰਾਂਸਪੋਰਟ ਨਾਲ ਬਦਲ ਦਿੱਤਾ ਗਿਆ ਹੈ। ਮੌਜੂਦਾ ਐਮਸੀਪੀ ਸਪੈਸਿਫਿਕੇਸ਼ਨ ਦੋ ਮੁੱਖ ਟ੍ਰਾਂਸਪੋਰਟ ਮਕੈਨਿਜ਼ਮਾਂ ਨੂੰ ਪਰਿਭਾਸ਼ਿਤ ਕਰਦਾ ਹੈ:
- stdio - ਸਟੈਂਡਰਡ ਇਨਪੁਟ/ਆਉਟਪੁੱਟ (ਸਥਾਨਕ ਸਰਵਰਾਂ ਲਈ ਸਿਫਾਰਸ਼ੀ)
- Streamable HTTP - ਦੂਰ-ਦਰਾਜ ਦੇ ਸਰਵਰਾਂ ਲਈ ਜੋ ਅੰਦਰੂਨੀ ਤੌਰ 'ਤੇ SSE ਵਰਤ ਸਕਦੇ ਹਨ
ਇਸ ਪਾਠ ਨੂੰ stdio ਟ੍ਰਾਂਸਪੋਰਟ 'ਤੇ ਧਿਆਨ ਕੇਂਦਰਿਤ ਕਰਨ ਲਈ ਅੱਪਡੇਟ ਕੀਤਾ ਗਿਆ ਹੈ, ਜੋ ਕਿ ਜ਼ਿਆਦਾਤਰ ਐਮਸੀਪੀ ਸਰਵਰ ਇੰਪਲੀਮੈਂਟੇਸ਼ਨ ਲਈ ਸਿਫਾਰਸ਼ੀ ਪਹੁੰਚ ਹੈ।
stdio ਟ੍ਰਾਂਸਪੋਰਟ ਐਮਸੀਪੀ ਸਰਵਰਾਂ ਨੂੰ ਸਟੈਂਡਰਡ ਇਨਪੁਟ ਅਤੇ ਆਉਟਪੁੱਟ ਸਟ੍ਰੀਮਾਂ ਰਾਹੀਂ ਕਲਾਇੰਟਾਂ ਨਾਲ ਸੰਚਾਰ ਕਰਨ ਦੀ ਆਗਿਆ ਦਿੰਦਾ ਹੈ। ਇਹ ਮੌਜੂਦਾ ਐਮਸੀਪੀ ਸਪੈਸਿਫਿਕੇਸ਼ਨ ਵਿੱਚ ਸਭ ਤੋਂ ਆਮ ਅਤੇ ਸਿਫਾਰਸ਼ੀ ਟ੍ਰਾਂਸਪੋਰਟ ਮਕੈਨਿਜ਼ਮ ਹੈ, ਜੋ ਐਮਸੀਪੀ ਸਰਵਰਾਂ ਨੂੰ ਬਣਾਉਣ ਦਾ ਇੱਕ ਸਧਾਰਨ ਅਤੇ ਪ੍ਰਭਾਵਸ਼ਾਲੀ ਤਰੀਕਾ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ ਜੋ ਵੱਖ-ਵੱਖ ਕਲਾਇੰਟ ਐਪਲੀਕੇਸ਼ਨਾਂ ਨਾਲ ਆਸਾਨੀ ਨਾਲ ਇੰਟੀਗਰੇਟ ਕੀਤਾ ਜਾ ਸਕਦਾ ਹੈ।
ਇਹ ਪਾਠ stdio ਟ੍ਰਾਂਸਪੋਰਟ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਐਮਸੀਪੀ ਸਰਵਰਾਂ ਨੂੰ ਬਣਾਉਣ ਅਤੇ ਉਪਭੋਗ ਕਰਨ ਦੇ ਤਰੀਕੇ ਨੂੰ ਕਵਰ ਕਰਦਾ ਹੈ।
ਇਸ ਪਾਠ ਦੇ ਅੰਤ ਤੱਕ, ਤੁਸੀਂ ਇਹ ਕਰਨ ਦੇ ਯੋਗ ਹੋਵੋਗੇ:
- stdio ਟ੍ਰਾਂਸਪੋਰਟ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਐਮਸੀਪੀ ਸਰਵਰ ਬਣਾਉਣਾ।
- ਇੰਸਪੈਕਟਰ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਐਮਸੀਪੀ ਸਰਵਰ ਨੂੰ ਡੀਬੱਗ ਕਰਨਾ।
- Visual Studio Code ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਐਮਸੀਪੀ ਸਰਵਰ ਨੂੰ ਉਪਭੋਗ ਕਰਨਾ।
- ਮੌਜੂਦਾ ਐਮਸੀਪੀ ਟ੍ਰਾਂਸਪੋਰਟ ਮਕੈਨਿਜ਼ਮਾਂ ਨੂੰ ਸਮਝਣਾ ਅਤੇ stdio ਦੀ ਸਿਫਾਰਸ਼ ਕਿਉਂ ਕੀਤੀ ਜਾਂਦੀ ਹੈ।
stdio ਟ੍ਰਾਂਸਪੋਰਟ ਮੌਜੂਦਾ ਐਮਸੀਪੀ ਸਪੈਸਿਫਿਕੇਸ਼ਨ (2025-06-18) ਵਿੱਚ ਸਮਰਥਿਤ ਦੋ ਟ੍ਰਾਂਸਪੋਰਟ ਕਿਸਮਾਂ ਵਿੱਚੋਂ ਇੱਕ ਹੈ। ਇਹ ਇਸ ਤਰੀਕੇ ਨਾਲ ਕੰਮ ਕਰਦਾ ਹੈ:
- ਸਧਾਰਨ ਸੰਚਾਰ: ਸਰਵਰ ਸਟੈਂਡਰਡ ਇਨਪੁਟ (
stdin) ਤੋਂ JSON-RPC ਸੁਨੇਹੇ ਪੜ੍ਹਦਾ ਹੈ ਅਤੇ ਸਟੈਂਡਰਡ ਆਉਟਪੁੱਟ (stdout) ਨੂੰ ਸੁਨੇਹੇ ਭੇਜਦਾ ਹੈ। - ਪ੍ਰੋਸੈਸ-ਅਧਾਰਿਤ: ਕਲਾਇੰਟ ਐਮਸੀਪੀ ਸਰਵਰ ਨੂੰ ਇੱਕ ਸਬਪ੍ਰੋਸੈਸ ਵਜੋਂ ਲਾਂਚ ਕਰਦਾ ਹੈ।
- ਸੁਨੇਹਾ ਫਾਰਮੈਟ: ਸੁਨੇਹੇ ਵਿਅਕਤੀਗਤ JSON-RPC ਬੇਨਤੀ, ਸੂਚਨਾਵਾਂ ਜਾਂ ਜਵਾਬ ਹੁੰਦੇ ਹਨ, ਜੋ ਨਵੀਂ ਲਾਈਨਾਂ ਦੁਆਰਾ ਵੱਖਰੇ ਕੀਤੇ ਜਾਂਦੇ ਹਨ।
- ਲੌਗਿੰਗ: ਸਰਵਰ ਲੌਗਿੰਗ ਦੇ ਉਦੇਸ਼ਾਂ ਲਈ ਸਟੈਂਡਰਡ ਐਰਰ (
stderr) 'ਤੇ UTF-8 ਸਟ੍ਰਿੰਗਾਂ ਲਿਖ ਸਕਦਾ ਹੈ।
- ਸੁਨੇਹੇ ਨਵੀਂ ਲਾਈਨਾਂ ਦੁਆਰਾ ਵੱਖਰੇ ਕੀਤੇ ਜਾਣੇ ਚਾਹੀਦੇ ਹਨ ਅਤੇ ਉਨ੍ਹਾਂ ਵਿੱਚ ਸਮਰਪਿਤ ਨਵੀਂ ਲਾਈਨਾਂ ਨਹੀਂ ਹੋਣੀਆਂ ਚਾਹੀਦੀਆਂ।
- ਸਰਵਰ
stdout'ਤੇ ਕੁਝ ਵੀ ਨਹੀਂ ਲਿਖੇਗਾ ਜੋ ਇੱਕ ਵੈਧ ਐਮਸੀਪੀ ਸੁਨੇਹਾ ਨਹੀਂ ਹੈ। - ਕਲਾਇੰਟ ਸਰਵਰ ਦੇ
stdin'ਤੇ ਕੁਝ ਵੀ ਨਹੀਂ ਲਿਖੇਗਾ ਜੋ ਇੱਕ ਵੈਧ ਐਮਸੀਪੀ ਸੁਨੇਹਾ ਨਹੀਂ ਹੈ।
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new Server(
{
name: "example-server",
version: "1.0.0",
},
{
capabilities: {
tools: {},
},
}
);ਉਪਰੋਕਤ ਕੋਡ ਵਿੱਚ:
- ਅਸੀਂ ਐਮਸੀਪੀ SDK ਤੋਂ
Serverਕਲਾਸ ਅਤੇStdioServerTransportਨੂੰ ਇੰਪੋਰਟ ਕਰਦੇ ਹਾਂ। - ਅਸੀਂ ਬੁਨਿਆਦੀ ਸੰਰਚਨਾ ਅਤੇ ਸਮਰੱਥਾਵਾਂ ਨਾਲ ਇੱਕ ਸਰਵਰ ਇੰਸਟੈਂਸ ਬਣਾਉਂਦੇ ਹਾਂ।
import asyncio
import logging
from mcp.server import Server
from mcp.server.stdio import stdio_server
# Create server instance
server = Server("example-server")
@server.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
async def main():
async with stdio_server(server) as (read_stream, write_stream):
await server.run(
read_stream,
write_stream,
server.create_initialization_options()
)
if __name__ == "__main__":
asyncio.run(main())ਉਪਰੋਕਤ ਕੋਡ ਵਿੱਚ ਅਸੀਂ:
- ਐਮਸੀਪੀ SDK ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਇੱਕ ਸਰਵਰ ਇੰਸਟੈਂਸ ਬਣਾਉਂਦੇ ਹਾਂ।
- ਡੈਕੋਰੇਟਰਾਂ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਟੂਲ ਪਰਿਭਾਸ਼ਿਤ ਕਰਦੇ ਹਾਂ।
- stdio_server ਕਾਂਟੈਕਸਟ ਮੈਨੇਜਰ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਟ੍ਰਾਂਸਪੋਰਟ ਨੂੰ ਸੰਭਾਲਦੇ ਹਾਂ।
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Server;
var builder = Host.CreateApplicationBuilder(args);
builder.Services
.AddMcpServer()
.WithStdioTransport()
.WithTools<Tools>();
builder.Services.AddLogging(logging => logging.AddConsole());
var app = builder.Build();
await app.RunAsync();SSE ਨਾਲ ਮੁੱਖ ਅੰਤਰ ਇਹ ਹੈ ਕਿ stdio ਸਰਵਰ:
- ਵੈੱਬ ਸਰਵਰ ਸੈਟਅਪ ਜਾਂ HTTP ਐਂਡਪੋਇੰਟ ਦੀ ਲੋੜ ਨਹੀਂ ਹੈ।
- ਕਲਾਇੰਟ ਦੁਆਰਾ ਸਬਪ੍ਰੋਸੈਸ ਵਜੋਂ ਲਾਂਚ ਕੀਤੇ ਜਾਂਦੇ ਹਨ।
- stdin/stdout ਸਟ੍ਰੀਮਾਂ ਰਾਹੀਂ ਸੰਚਾਰ ਕਰਦੇ ਹਨ।
- ਲਾਗੂ ਕਰਨ ਅਤੇ ਡੀਬੱਗ ਕਰਨ ਲਈ ਸਧਾਰਨ ਹਨ।
ਸਾਡਾ ਸਰਵਰ ਬਣਾਉਣ ਲਈ, ਸਾਨੂੰ ਦੋ ਗੱਲਾਂ ਦਾ ਧਿਆਨ ਰੱਖਣਾ ਪਵੇਗਾ:
- ਸਾਨੂੰ ਕਨੈਕਸ਼ਨ ਅਤੇ ਸੁਨੇਹਿਆਂ ਲਈ ਐਂਡਪੋਇੰਟਸ ਨੂੰ ਉਜਾਗਰ ਕਰਨ ਲਈ ਇੱਕ ਵੈੱਬ ਸਰਵਰ ਦੀ ਲੋੜ ਹੈ।
ਇਸ ਲੈਬ ਵਿੱਚ, ਅਸੀਂ stdio ਟ੍ਰਾਂਸਪੋਰਟ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਇੱਕ ਸਧਾਰਨ ਐਮਸੀਪੀ ਸਰਵਰ ਬਣਾਵਾਂਗੇ। ਇਹ ਸਰਵਰ ਉਹ ਟੂਲ ਉਜਾਗਰ ਕਰੇਗਾ ਜੋ ਕਲਾਇੰਟ ਸਟੈਂਡਰਡ ਮਾਡਲ ਕਾਂਟੈਕਸਟ ਪ੍ਰੋਟੋਕੋਲ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਕਾਲ ਕਰ ਸਕਦੇ ਹਨ।
- Python 3.8 ਜਾਂ ਇਸ ਤੋਂ ਉੱਚਾ
- ਐਮਸੀਪੀ ਪਾਈਥਨ SDK:
pip install mcp - async ਪ੍ਰੋਗਰਾਮਿੰਗ ਦੀ ਬੁਨਿਆਦੀ ਸਮਝ
ਆਓ ਆਪਣਾ ਪਹਿਲਾ ਐਮਸੀਪੀ stdio ਸਰਵਰ ਬਣਾਉਣਾ ਸ਼ੁਰੂ ਕਰੀਏ:
import asyncio
import logging
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp import types
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Create the server
server = Server("example-stdio-server")
@server.tool()
def calculate_sum(a: int, b: int) -> int:
"""Calculate the sum of two numbers"""
return a + b
@server.tool()
def get_greeting(name: str) -> str:
"""Generate a personalized greeting"""
return f"Hello, {name}! Welcome to MCP stdio server."
async def main():
# Use stdio transport
async with stdio_server(server) as (read_stream, write_stream):
await server.run(
read_stream,
write_stream,
server.create_initialization_options()
)
if __name__ == "__main__":
asyncio.run(main())Stdio ਟ੍ਰਾਂਸਪੋਰਟ (ਮੌਜੂਦਾ ਮਿਆਰ):
- ਸਧਾਰਨ ਸਬਪ੍ਰੋਸੈਸ ਮਾਡਲ - ਕਲਾਇੰਟ ਸਰਵਰ ਨੂੰ ਚਾਈਲਡ ਪ੍ਰੋਸੈਸ ਵਜੋਂ ਲਾਂਚ ਕਰਦਾ ਹੈ।
- stdin/stdout ਰਾਹੀਂ JSON-RPC ਸੁਨੇਹਿਆਂ ਦੁਆਰਾ ਸੰਚਾਰ।
- HTTP ਸਰਵਰ ਸੈਟਅਪ ਦੀ ਲੋੜ ਨਹੀਂ।
- ਬਿਹਤਰ ਪ੍ਰਦਰਸ਼ਨ ਅਤੇ ਸੁਰੱਖਿਆ।
- ਡੀਬੱਗਿੰਗ ਅਤੇ ਵਿਕਾਸ ਲਈ ਆਸਾਨ।
SSE ਟ੍ਰਾਂਸਪੋਰਟ (ਐਮਸੀਪੀ 2025-06-18 ਦੇ ਤਹਿਤ ਡਿਪ੍ਰੀਕੇਟ):
- HTTP ਸਰਵਰ ਨਾਲ SSE ਐਂਡਪੋਇੰਟਸ ਦੀ ਲੋੜ ਸੀ।
- ਵੈੱਬ ਸਰਵਰ ਇੰਫਰਾਸਟਰਕਚਰ ਨਾਲ ਜਟਿਲ ਸੈਟਅਪ।
- HTTP ਐਂਡਪੋਇੰਟਸ ਲਈ ਵਾਧੂ ਸੁਰੱਖਿਆ ਵਿਚਾਰ।
- ਹੁਣ ਵੈੱਬ-ਅਧਾਰਿਤ ਸਥਿਤੀਆਂ ਲਈ Streamable HTTP ਨਾਲ ਬਦਲ ਦਿੱਤਾ ਗਿਆ।
stdio ਸਰਵਰ ਬਣਾਉਣ ਲਈ, ਸਾਨੂੰ ਇਹ ਕਰਨ ਦੀ ਲੋੜ ਹੈ:
- ਲੋੜੀਂਦੇ ਲਾਇਬ੍ਰੇਰੀਆਂ ਇੰਪੋਰਟ ਕਰੋ - ਸਾਨੂੰ ਐਮਸੀਪੀ ਸਰਵਰ ਕੰਪੋਨੈਂਟਸ ਅਤੇ stdio ਟ੍ਰਾਂਸਪੋਰਟ ਦੀ ਲੋੜ ਹੈ।
- ਸਰਵਰ ਇੰਸਟੈਂਸ ਬਣਾਓ - ਸਰਵਰ ਨੂੰ ਇਸ ਦੀ ਸਮਰੱਥਾਵਾਂ ਨਾਲ ਪਰਿਭਾਸ਼ਿਤ ਕਰੋ।
- ਟੂਲ ਪਰਿਭਾਸ਼ਿਤ ਕਰੋ - ਉਹ ਕਾਰਜਸ਼ੀਲਤਾ ਸ਼ਾਮਲ ਕਰੋ ਜੋ ਅਸੀਂ ਉਜਾਗਰ ਕਰਨਾ ਚਾਹੁੰਦੇ ਹਾਂ।
- ਟ੍ਰਾਂਸਪੋਰਟ ਸੈਟਅਪ ਕਰੋ - stdio ਸੰਚਾਰ ਨੂੰ ਸੰਰਚਿਤ ਕਰੋ।
- ਸਰਵਰ ਚਲਾਓ - ਸਰਵਰ ਸ਼ੁਰੂ ਕਰੋ ਅਤੇ ਸੁਨੇਹਿਆਂ ਨੂੰ ਸੰਭਾਲੋ।
ਆਓ ਇਸਨੂੰ ਕਦਮ-ਦਰ-ਕਦਮ ਬਣਾਈਏ:
import asyncio
import logging
from mcp.server import Server
from mcp.server.stdio import stdio_server
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Create the server
server = Server("example-stdio-server")
@server.tool()
def get_greeting(name: str) -> str:
"""Generate a personalized greeting"""
return f"Hello, {name}! Welcome to MCP stdio server."
async def main():
async with stdio_server(server) as (read_stream, write_stream):
await server.run(
read_stream,
write_stream,
server.create_initialization_options()
)
if __name__ == "__main__":
asyncio.run(main())@server.tool()
def calculate_sum(a: int, b: int) -> int:
"""Calculate the sum of two numbers"""
return a + b
@server.tool()
def calculate_product(a: int, b: int) -> int:
"""Calculate the product of two numbers"""
return a * b
@server.tool()
def get_server_info() -> dict:
"""Get information about this MCP server"""
return {
"server_name": "example-stdio-server",
"version": "1.0.0",
"transport": "stdio",
"capabilities": ["tools"]
}ਕੋਡ ਨੂੰ server.py ਵਜੋਂ ਸੇਵ ਕਰੋ ਅਤੇ ਕਮਾਂਡ ਲਾਈਨ ਤੋਂ ਚਲਾਓ:
python server.pyਸਰਵਰ ਸ਼ੁਰੂ ਹੋਵੇਗਾ ਅਤੇ stdin ਤੋਂ ਇਨਪੁਟ ਦੀ ਉਡੀਕ ਕਰੇਗਾ। ਇਹ stdio ਟ੍ਰਾਂਸਪੋਰਟ ਰਾਹੀਂ JSON-RPC ਸੁਨੇਹਿਆਂ ਨਾਲ ਸੰਚਾਰ ਕਰਦਾ ਹੈ।
ਤੁਸੀਂ ਆਪਣੇ ਸਰਵਰ ਨੂੰ ਐਮਸੀਪੀ ਇੰਸਪੈਕਟਰ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਟੈਸਟ ਕਰ ਸਕਦੇ ਹੋ:
- ਇੰਸਪੈਕਟਰ ਇੰਸਟਾਲ ਕਰੋ:
npx @modelcontextprotocol/inspector - ਇੰਸਪੈਕਟਰ ਚਲਾਓ ਅਤੇ ਇਸਨੂੰ ਆਪਣੇ ਸਰਵਰ ਵੱਲ ਪੋਇੰਟ ਕਰੋ।
- ਉਹ ਟੂਲ ਟੈਸਟ ਕਰੋ ਜੋ ਤੁਸੀਂ ਬਣਾਏ ਹਨ।
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddMcpServer();
## Debugging your stdio server
### Using the MCP Inspector
The MCP Inspector is a valuable tool for debugging and testing MCP servers. Here's how to use it with your stdio server:
1. **Install the Inspector**:
```bash
npx @modelcontextprotocol/inspector-
Run the Inspector:
npx @modelcontextprotocol/inspector python server.py
-
Test your server: The Inspector provides a web interface where you can:
- View server capabilities
- Test tools with different parameters
- Monitor JSON-RPC messages
- Debug connection issues
You can also debug your MCP server directly in VS Code:
-
Create a launch configuration in
.vscode/launch.json:{ "version": "0.2.0", "configurations": [ { "name": "Debug MCP Server", "type": "python", "request": "launch", "program": "server.py", "console": "integratedTerminal" } ] } -
Set breakpoints in your server code
-
Run the debugger and test with the Inspector
- Use
stderrfor logging - never write tostdoutas it's reserved for MCP messages - Ensure all JSON-RPC messages are newline-delimited
- Test with simple tools first before adding complex functionality
- Use the Inspector to verify message formats
Once you've built your MCP stdio server, you can integrate it with VS Code to use it with Claude or other MCP-compatible clients.
-
Create an MCP configuration file at
%APPDATA%\Claude\claude_desktop_config.json(Windows) or~/Library/Application Support/Claude/claude_desktop_config.json(Mac):{ "mcpServers": { "example-stdio-server": { "command": "python", "args": ["path/to/your/server.py"] } } } -
Restart Claude: Close and reopen Claude to load the new server configuration.
-
Test the connection: Start a conversation with Claude and try using your server's tools:
- "Can you greet me using the greeting tool?"
- "Calculate the sum of 15 and 27"
- "What's the server info?"
Here's a complete TypeScript example for reference:
#!/usr/bin/env node
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
const server = new Server(
{
name: "example-stdio-server",
version: "1.0.0",
},
{
capabilities: {
tools: {},
},
}
);
// Add tools
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "get_greeting",
description: "Get a personalized greeting",
inputSchema: {
type: "object",
properties: {
name: {
type: "string",
description: "Name of the person to greet",
},
},
required: ["name"],
},
},
],
};
});
server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (request.params.name === "get_greeting") {
return {
content: [
{
type: "text",
text: `Hello, ${request.params.arguments?.name}! Welcome to MCP stdio server.`,
},
],
};
} else {
throw new Error(`Unknown tool: ${request.params.name}`);
}
});
async function runServer() {
const transport = new StdioServerTransport();
await server.connect(transport);
}
runServer().catch(console.error);using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Server;
using System.ComponentModel;
var builder = Host.CreateApplicationBuilder(args);
builder.Services
.AddMcpServer()
.WithStdioTransport()
.WithTools<Tools>();
var app = builder.Build();
await app.RunAsync();
public class Tools
{
[Description("Get a personalized greeting")]
public string GetGreeting(string name)
{
return $"Hello, {name}! Welcome to MCP stdio server.";
}
[Description("Calculate the sum of two numbers")]
public int CalculateSum(int a, int b)
{
return a + b;
}
}In this updated lesson, you learned how to:
- Build MCP servers using the current stdio transport (recommended approach)
- Understand why SSE transport was deprecated in favor of stdio and Streamable HTTP
- Create tools that can be called by MCP clients
- Debug your server using the MCP Inspector
- Integrate your stdio server with VS Code and Claude
The stdio transport provides a simpler, more secure, and more performant way to build MCP servers compared to the deprecated SSE approach. It's the recommended transport for most MCP server implementations as of the 2025-06-18 specification.
### .NET
1. ਪਹਿਲਾਂ ਕੁਝ ਟੂਲ ਬਣਾਉਣ ਲਈ, ਅਸੀਂ *Tools.cs* ਫਾਈਲ ਬਣਾਵਾਂਗੇ ਜਿਸ ਵਿੱਚ ਹੇਠਾਂ ਦਿੱਤਾ ਸਮੱਗਰੀ ਹੋਵੇਗਾ:
```csharp
using System.ComponentModel;
using System.Text.Json;
using ModelContextProtocol.Server;
## Exercise: Testing your stdio server
Now that you've built your stdio server, let's test it to make sure it works correctly.
### Prerequisites
1. Ensure you have the MCP Inspector installed:
```bash
npm install -g @modelcontextprotocol/inspector
- Your server code should be saved (e.g., as
server.py)
-
Start the Inspector with your server:
npx @modelcontextprotocol/inspector python server.py
-
ਵੈੱਬ ਇੰਟਰਫੇਸ ਖੋਲ੍ਹੋ: ਇੰਸਪੈਕਟਰ ਇੱਕ ਬ੍ਰਾਊਜ਼ਰ ਵਿੰਡੋ ਖੋਲ੍ਹੇਗਾ ਜੋ ਤੁਹਾਡੇ ਸਰਵਰ ਦੀ ਸਮਰੱਥਾਵਾਂ ਦਿਖਾਉਂਦਾ ਹੈ।
-
ਟੂਲ ਟੈਸਟ ਕਰੋ:
- ਵੱਖ-ਵੱਖ ਨਾਮਾਂ ਨਾਲ
get_greetingਟੂਲ ਦੀ ਕੋਸ਼ਿਸ਼ ਕਰੋ। - ਵੱਖ-ਵੱਖ ਨੰਬਰਾਂ ਨਾਲ
calculate_sumਟੂਲ ਦੀ ਕੋਸ਼ਿਸ਼ ਕਰੋ। - ਸਰਵਰ ਮੈਟਾਡੇਟਾ ਦੇਖਣ ਲਈ
get_server_infoਟੂਲ ਨੂੰ ਕਾਲ ਕਰੋ।
- ਵੱਖ-ਵੱਖ ਨਾਮਾਂ ਨਾਲ
-
ਸੰਚਾਰ ਦੀ ਨਿਗਰਾਨੀ ਕਰੋ: ਇੰਸਪੈਕਟਰ JSON-RPC ਸੁਨੇਹਿਆਂ ਨੂੰ ਦਿਖਾਉਂਦਾ ਹੈ ਜੋ ਕਲਾਇੰਟ ਅਤੇ ਸਰਵਰ ਦੇ ਵਿਚਕਾਰ ਅਦਲ-ਬਦਲ ਕੀਤੇ ਜਾ ਰਹੇ ਹਨ।
ਜਦੋਂ ਤੁਹਾਡਾ ਸਰਵਰ ਸਹੀ ਤਰੀਕੇ ਨਾਲ ਸ਼ੁਰੂ ਹੁੰਦਾ ਹੈ, ਤਾਂ ਤੁਸੀਂ ਇਹ ਦੇਖੋਗੇ:
- ਇੰਸਪੈਕਟਰ ਵਿੱਚ ਸਰਵਰ ਦੀ ਸਮਰੱਥਾਵਾਂ ਦੀ ਸੂਚੀ।
- ਟੈਸਟ ਕਰਨ ਲਈ ਉਪਲਬਧ ਟੂਲ।
- ਸਫਲ JSON-RPC ਸੁਨੇਹਾ ਅਦਲ-ਬਦਲ।
- ਇੰਟਰਫੇਸ ਵਿੱਚ ਟੂਲ ਜਵਾਬ ਦਿਖਾਏ ਗਏ।
ਸਰਵਰ ਸ਼ੁਰੂ ਨਹੀਂ ਹੋ ਰਿਹਾ:
- ਸਾਰੇ ਡਿਪੈਂਡੈਂਸੀਜ਼ ਇੰਸਟਾਲ ਕੀਤੇ ਗਏ ਹਨ ਜਾਂ ਨਹੀਂ:
pip install mcp। - Python ਸਿੰਟੈਕਸ ਅਤੇ ਇੰਡੈਂਟੇਸ਼ਨ ਦੀ ਜਾਂਚ ਕਰੋ।
- ਕਨਸੋਲ ਵਿੱਚ ਐਰਰ ਸੁਨੇਹਿਆਂ ਦੀ ਜਾਂਚ ਕਰੋ।
ਟੂਲ ਦਿਖਾਈ ਨਹੀਂ ਦੇ ਰਹੇ:
- ਯਕੀਨੀ ਬਣਾਓ ਕਿ
@server.tool()ਡੈਕੋਰੇਟਰ ਮੌਜੂਦ ਹਨ। - ਯਕੀਨੀ ਬਣਾਓ ਕਿ ਟੂਲ ਫੰਕਸ਼ਨ
main()ਤੋਂ ਪਹਿਲਾਂ ਪਰਿਭਾਸ਼ਿਤ ਕੀਤੇ ਗਏ ਹਨ। - ਸਰਵਰ ਸਹੀ ਤਰੀਕੇ ਨਾਲ ਸੰਰਚਿਤ ਹੈ ਜਾਂ ਨਹੀਂ ਦੀ ਜਾਂਚ ਕਰੋ।
ਕਨੈਕਸ਼ਨ ਸਮੱਸਿਆਵਾਂ:
- ਯਕੀਨੀ ਬਣਾਓ ਕਿ ਸਰਵਰ stdio ਟ੍ਰਾਂਸਪੋਰਟ ਨੂੰ ਸਹੀ ਤਰੀਕੇ ਨਾਲ ਵਰਤ ਰਿਹਾ ਹੈ।
- ਯਕੀਨੀ ਬਣਾਓ ਕਿ ਹੋਰ ਪ੍ਰੋਸੈਸੇਜ਼ ਦਖਲ ਨਹੀਂ ਦੇ ਰਹੇ।
- ਇੰਸਪੈਕਟਰ ਕਮਾਂਡ ਸਿੰਟੈਕਸ ਦੀ ਜਾਂਚ ਕਰੋ।
ਆਪਣੇ ਸਰਵਰ ਨੂੰ ਹੋਰ ਸਮਰੱਥਾਵਾਂ ਨਾਲ ਬਣਾਉਣ ਦੀ ਕੋਸ਼ਿਸ਼ ਕਰੋ। ਇਸ ਪੇਜ ਨੂੰ ਦੇਖੋ, ਉਦਾਹਰਣ ਲਈ, ਇੱਕ ਟੂਲ ਸ਼ਾਮਲ ਕਰਨ ਲਈ ਜੋ API ਨੂੰ ਕਾਲ ਕਰਦਾ ਹੈ। ਤੁਸੀਂ ਫੈਸਲਾ ਕਰੋ ਕਿ ਸਰਵਰ ਕਿਵ
ਅਸਵੀਕਾਰਨਾ:
ਇਹ ਦਸਤਾਵੇਜ਼ AI ਅਨੁਵਾਦ ਸੇਵਾ Co-op Translator ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਅਨੁਵਾਦ ਕੀਤਾ ਗਿਆ ਹੈ। ਜਦੋਂ ਕਿ ਅਸੀਂ ਸਹੀ ਹੋਣ ਦੀ ਕੋਸ਼ਿਸ਼ ਕਰਦੇ ਹਾਂ, ਕਿਰਪਾ ਕਰਕੇ ਧਿਆਨ ਦਿਓ ਕਿ ਸਵੈਚਾਲਿਤ ਅਨੁਵਾਦਾਂ ਵਿੱਚ ਗਲਤੀਆਂ ਜਾਂ ਅਸੁਚੱਜੇਪਣ ਹੋ ਸਕਦੇ ਹਨ। ਮੂਲ ਦਸਤਾਵੇਜ਼, ਜੋ ਇਸਦੀ ਮੂਲ ਭਾਸ਼ਾ ਵਿੱਚ ਹੈ, ਨੂੰ ਅਧਿਕਾਰਤ ਸਰੋਤ ਮੰਨਿਆ ਜਾਣਾ ਚਾਹੀਦਾ ਹੈ। ਮਹੱਤਵਪੂਰਨ ਜਾਣਕਾਰੀ ਲਈ, ਪੇਸ਼ੇਵਰ ਮਨੁੱਖੀ ਅਨੁਵਾਦ ਦੀ ਸਿਫਾਰਸ਼ ਕੀਤੀ ਜਾਂਦੀ ਹੈ। ਇਸ ਅਨੁਵਾਦ ਦੀ ਵਰਤੋਂ ਤੋਂ ਪੈਦਾ ਹੋਣ ਵਾਲੇ ਕਿਸੇ ਵੀ ਗਲਤਫਹਿਮੀ ਜਾਂ ਗਲਤ ਵਿਆਖਿਆ ਲਈ ਅਸੀਂ ਜ਼ਿੰਮੇਵਾਰ ਨਹੀਂ ਹਾਂ।