Releases: punkpeye/fastmcp
Releases · punkpeye/fastmcp
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
1.20.0 (2025-02-26)
FastMCP now allows you to authenticate
SSE clients using a custom function:
import { AuthError } from "fastmcp";
const server = new FastMCP({
name: "My Server",
version: "1.0.0",
authenticate: ({request}) => {
const apiKey = request.headers["x-api-key"];
if (apiKey !== '123') {
throw new Response(null, {
status: 401,
statusText: "Unauthorized",
});
}
// Whatever you return here will be accessible in the `context.session` object.
return {
id: 1,
}
},
});
Now you can access the authenticated user's data in your tools:
server.addTool({
name: "sayHello",
execute: async (args, { session }) => {
return `Hello, ${session.id}!`;
},
});