agent0-js 0.0.15 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/types.ts +5 -0
package/README.md
CHANGED
|
@@ -91,6 +91,9 @@ interface RunOptions {
|
|
|
91
91
|
overrides?: ModelOverrides; // Runtime model configuration overrides
|
|
92
92
|
extraMessages?: Message[]; // Extra messages to append to the prompt
|
|
93
93
|
extraTools?: CustomTool[]; // Additional custom tools to add at runtime
|
|
94
|
+
mcpOptions?: Record<string, { // Per-MCP server runtime options (keyed by MCP ID)
|
|
95
|
+
headers?: Record<string, string>; // Custom HTTP headers to send with MCP requests
|
|
96
|
+
}>;
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
interface CustomTool {
|
|
@@ -738,6 +741,54 @@ for await (const chunk of stream) {
|
|
|
738
741
|
}
|
|
739
742
|
```
|
|
740
743
|
|
|
744
|
+
### MCP Custom Headers (`mcpOptions`)
|
|
745
|
+
|
|
746
|
+
If your MCP servers require dynamic headers at runtime (e.g., authentication tokens, tenant IDs), you can pass them via `mcpOptions`. First, configure the header names on your MCP server in the Agent0 dashboard (under **Custom Headers**), then provide the values at runtime.
|
|
747
|
+
|
|
748
|
+
Headers are keyed by MCP server ID:
|
|
749
|
+
|
|
750
|
+
```typescript
|
|
751
|
+
const response = await client.generate({
|
|
752
|
+
agentId: 'agent_123',
|
|
753
|
+
mcpOptions: {
|
|
754
|
+
'mcp-server-id-1': {
|
|
755
|
+
headers: {
|
|
756
|
+
'X-User-Token': 'bearer-token-here',
|
|
757
|
+
'X-Tenant-Id': 'tenant-456'
|
|
758
|
+
}
|
|
759
|
+
},
|
|
760
|
+
'mcp-server-id-2': {
|
|
761
|
+
headers: {
|
|
762
|
+
'Authorization': 'Bearer another-token'
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
```
|
|
768
|
+
|
|
769
|
+
**Streaming with Custom Headers:**
|
|
770
|
+
|
|
771
|
+
```typescript
|
|
772
|
+
const stream = client.stream({
|
|
773
|
+
agentId: 'agent_123',
|
|
774
|
+
mcpOptions: {
|
|
775
|
+
'mcp-server-id': {
|
|
776
|
+
headers: {
|
|
777
|
+
'X-User-Token': userSession.token
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
for await (const chunk of stream) {
|
|
784
|
+
if (chunk.type === 'text-delta') {
|
|
785
|
+
process.stdout.write(chunk.textDelta);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
> ⚠️ **Note**: Only header names that are pre-configured as "Custom Headers" on the MCP server will be sent. Any extra headers not in the allowed list are ignored.
|
|
791
|
+
|
|
741
792
|
### Error Handling
|
|
742
793
|
|
|
743
794
|
```typescript
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -61,6 +61,7 @@ export class Agent0 {
|
|
|
61
61
|
overrides: options.overrides,
|
|
62
62
|
extra_messages: options.extraMessages,
|
|
63
63
|
extra_tools: options.extraTools,
|
|
64
|
+
mcp_options: options.mcpOptions,
|
|
64
65
|
stream: false,
|
|
65
66
|
});
|
|
66
67
|
|
|
@@ -77,6 +78,7 @@ export class Agent0 {
|
|
|
77
78
|
overrides: options.overrides,
|
|
78
79
|
extra_messages: options.extraMessages,
|
|
79
80
|
extra_tools: options.extraTools,
|
|
81
|
+
mcp_options: options.mcpOptions,
|
|
80
82
|
stream: true,
|
|
81
83
|
});
|
|
82
84
|
|
package/src/types.ts
CHANGED
|
@@ -78,6 +78,11 @@ export interface RunOptions {
|
|
|
78
78
|
extraMessages?: ModelMessage[];
|
|
79
79
|
/** Additional custom tools to add at runtime. These are merged with any tools defined in the agent. */
|
|
80
80
|
extraTools?: CustomTool[];
|
|
81
|
+
/** Per-MCP server runtime options, keyed by MCP server ID. */
|
|
82
|
+
mcpOptions?: Record<string, {
|
|
83
|
+
/** Custom headers to send to this MCP server */
|
|
84
|
+
headers?: Record<string, string>;
|
|
85
|
+
}>;
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
export interface GenerateResponse {
|