Skip to content

Commit 7bcf907

Browse files
authored
Merge pull request #159 from tavily-ai/chore/add-human-id-support
Chore/add human id support
2 parents 2911172 + c916af4 commit 7bcf907

4 files changed

Lines changed: 33 additions & 5 deletions

File tree

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,29 @@ export DEFAULT_PARAMETERS='{"include_images": true}'
206206
}
207207
```
208208

209+
## Identifying the End User (Optional)
210+
211+
You can optionally identify the end user on whose behalf requests are being made by setting the `TAVILY_HUMAN_ID` environment variable. When set, Tavily MCP forwards it as the `X-Human-Id` header on every API call, enabling per-user analytics.
212+
213+
This is **entirely optional** — leave it unset and behavior is unchanged.
214+
215+
```json
216+
{
217+
"mcpServers": {
218+
"tavily-mcp": {
219+
"command": "npx",
220+
"args": ["-y", "tavily-mcp@latest"],
221+
"env": {
222+
"TAVILY_API_KEY": "your-api-key-here",
223+
"TAVILY_HUMAN_ID": "your-user-id"
224+
}
225+
}
226+
}
227+
}
228+
```
229+
230+
**Privacy note:** Tavily hashes `human_id` server-side (SHA-256) before storage, so the raw value is never persisted. Even so, prefer opaque identifiers (e.g. an internal user ID) over raw PII like emails when possible.
231+
209232
## Acknowledgments ✨
210233

211234
- [Model Context Protocol](https://modelcontextprotocol.io) for the MCP specification

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tavily-mcp",
3-
"version": "0.2.18",
3+
"version": "0.2.19",
44
"mcpName": "io.github.tavily-ai/tavily-mcp",
55
"description": "MCP server for advanced web search using Tavily",
66
"repository": {

src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
44
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
55
import {CallToolRequestSchema, ListToolsRequestSchema, Tool} from "@modelcontextprotocol/sdk/types.js";
66
import axios from "axios";
7+
import { randomUUID } from "crypto";
78
import dotenv from "dotenv";
89
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
910
import yargs from 'yargs';
@@ -12,6 +13,8 @@ import { hideBin } from 'yargs/helpers';
1213
dotenv.config();
1314

1415
const API_KEY = process.env.TAVILY_API_KEY;
16+
const HUMAN_ID = process.env.TAVILY_HUMAN_ID;
17+
const SESSION_ID = randomUUID();
1518

1619

1720
interface TavilyResponse {
@@ -81,7 +84,7 @@ class TavilyClient {
8184
this.server = new Server(
8285
{
8386
name: "tavily-mcp",
84-
version: "0.2.18",
87+
version: "0.2.19",
8588
},
8689
{
8790
capabilities: {
@@ -95,7 +98,9 @@ class TavilyClient {
9598
'accept': 'application/json',
9699
'content-type': 'application/json',
97100
'Authorization': `Bearer ${API_KEY}`,
98-
'X-Client-Source': 'MCP'
101+
'X-Client-Source': 'MCP',
102+
'X-Session-Id': SESSION_ID,
103+
...(HUMAN_ID ? { 'X-Human-Id': HUMAN_ID } : {}),
99104
}
100105
});
101106

0 commit comments

Comments
 (0)