You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+119Lines changed: 119 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ A TypeScript framework for building [MCP](https://glama.ai/mcp) servers capable
10
10
11
11
- Simple Tool, Resource, Prompt definition
12
12
-[Authentication](#authentication)
13
+
-[Passing headers through context](#passing-headers-through-context)
13
14
-[Sessions](#sessions)
14
15
-[Image content](#returning-an-image)
15
16
-[Audio content](#returning-an-audio)
@@ -1161,6 +1162,124 @@ server.addTool({
1161
1162
});
1162
1163
```
1163
1164
1165
+
#### Passing Headers Through Context
1166
+
1167
+
If you are exposing your MCP server via HTTP, you may wish to allow clients to supply sensitive keys via headers, which can then be passed along to APIs that your tools interact with, allowing each client to supply their own API keys. This can be done by capturing the HTTP headers in the `authenticate` section and storing them in the session to be referenced by the tools later.
1168
+
1169
+
```ts
1170
+
import { FastMCP } from'fastmcp';
1171
+
import { IncomingHttpHeaders } from'http';
1172
+
1173
+
// Define the session data type
1174
+
interfaceSessionData {
1175
+
headers:IncomingHttpHeaders;
1176
+
[key:string]:unknown; // Add index signature to satisfy Record<string, unknown>
0 commit comments