server.tool(
"greet",
"A simple greeting tool",
{
name: z.string().describe("Name to greet"),
},
async (
args: { name: string },
extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
): Promise<CallToolResult> => {
const apiKey = extra.requestInfo?.headers["x-api-key"];
if (!apiKey) {
return {
content: [
isError: true,
{
type: "text",
text: `You need to have a valid api key to use this tool.`,
},
],
};
}
const yourApiClient = new yourApiClient(apiKey);
const yourApiResponse = await yourApiClient.greet(name);
return {
content: [
{
type: "text",
text: `${yourApiResponse}`,
},
],
};
},
);
from mcp.server.fastmcp import Context, FastMCP
from pydantic import Field
mcp = FastMCP("Echo Server", stateless_http=True)
@mcp.tool(
title="Echo Tool",
description="Echo the input text",
)
async def echo(ctx: Context, text: str = Field(description="The text to echo")) -> str:
api_key = ctx.request_context.request.get("x-api-key")
if not api_key:
raise ValueError("API key is required")
your_api_client = YourApiClient(api_key)
your_api_response = await your_api_client.echo(text)
return your_api_response
{
"mcpServers": {
"yourMcpServer": {
"url": "https://your-mcp-server.alpic.live",
"headers": {
"x-api-key": "<USER_API_KEY>"
}
}
}
}
{
"mcpServers": {
"yourMcpServer": {
"command": "npx",
"args": ["mcp-remote", "https://your-mcp-server.alpic.live", "--header", "x-api-key: <USER_API_KEY>"]
}
}
}
code --add-mcp '{"type":"http","name":"yourMcpServer","version":"0.0.1","description":"your amazing server","url":"https://your-mcp-server.alpic.live","author":"You","categories":["mcp"],"headers":{"x-api-key":"<USER_API_KEY>"}}'
claude mcp add --transport http yourMcpServer https://your-mcp-server.alpic.live \
--header "x-api-key: <USER_API_KEY>"
Go to Extensions
Click on Add custom extension
Fill the following information:
- Extension Name: yourMcpServer
- Type: Streamable HTTP
- Description: Your amazing MCP server
- Endpoint: https://your-mcp-server.alpic.live
Enter authentication headers:
Scroll down to the Request Headers section
Click the + Add button
Enter Header name: x-api-key
Enter Value: <USER_API_KEY>