Skip to content

Commit 67b8d35

Browse files
authored
update sdk credentials docs (#457)
* update sdk credentials docs * address comments
1 parent c689d06 commit 67b8d35

File tree

2 files changed

+170
-91
lines changed

2 files changed

+170
-91
lines changed

agents-docs/content/docs/typescript-sdk/create-mcp-servers.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Vercel provides a [Next.js MCP template](https://vercel.com/templates/next.js/mo
2929
Vercel's template provides:
3030
- **Easy to deploy** staging environments
3131
- **Serverless deployment** for automatic scaling with Vercel Functions
32-
- **SSE transport** for eal-time streaming (requires Redis for state management)
32+
- **SSE transport** for real-time streaming (requires Redis for state management)
3333
- **Next.js integration** so MCPs can be added as part of existing Next.js apps
3434

3535
#### Quick start
@@ -107,7 +107,6 @@ const composioTool = mcpTool({
107107
name: 'Composio Integration',
108108
description: 'Access popular SaaS tools via Composio',
109109
serverUrl: 'YOUR_COMPOSIO_MCP_URL', // From Composio dashboard
110-
// Optionally: credentialReferenceId: 'your-credential-id',
111110
});
112111
```
113112

agents-docs/content/docs/typescript-sdk/credentials.mdx

Lines changed: 169 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,126 +6,206 @@ icon: "LuKey"
66

77
Securely store and retrieve authentication credentials for MCP servers.
88

9-
## Step 1: Add a credential
9+
## How Credential Storage Works
1010

11-
<Snippet file="multi-agent-framework/add-a-credential.mdx" />
11+
**Key concepts:**
12+
- **Credential stores** handle the actual storage and retrieval of credential data
13+
- **Credential references** define how to find and use stored credentials
14+
- **TypeScript SDK vs Visual Builder** offer different creation methods depending on the credential type
1215

13-
## Step 2: Retrieve the credential reference id from the URLs
16+
The framework uses a system that stores references to credentials and retrieves the actual credential values at runtime. When you define a credential, you're creating a reference that tells the system where and how to find the credential data. The actual credential is fetched at runtime and injected into the authorization headers for MCP tools.
1417

15-
Once you've created a credential, you can retrieve the credential reference id from the URL. The credential reference id is the last part of the URL after `credentials/` on the page of the credential you just created.
18+
**Key limitations**: The TypeScript SDK can only directly create **Memory store** credentials. Nango and Keychain stores require OAuth authorization flows with user interaction, which are handled through the Visual Builder interface.
1619

17-
## Step 3: Reference the credential when creating an MCP tool
20+
## Credential Store Types
1821

19-
There are two ways to reference credentials in your MCP tools:
22+
The framework supports three credential store types, each suited for different authentication patterns.
2023

21-
### Option 1: Reference by Credential ID (Recommended)
24+
### Memory Store
25+
**Common use case**: Simple API keys and bearer tokens stored in environment variables. Configured directly through the TypeScript SDK.
2226

23-
When you create a credential through the UI, you get a credential reference ID that you can use directly:
27+
- Credentials retrieved from environment variables at runtime
28+
- Suitable for both development and production environments
29+
- Direct configuration via `credential()` function in TypeScript SDK
2430

25-
```typescript
26-
import { mcpTool, MCPTransportType } from '@inkeep/agents-sdk';
27-
28-
// Use the credential reference ID from the UI
29-
const inkeepAnalyticsTool = mcpTool({
30-
id: 'inkeep-analytics',
31-
name: 'inkeep_analytics',
32-
description: 'Get the latest stats from the Inkeep Analytics dashboard',
33-
serverUrl: 'https://analytics.inkeep.com/mcp',
34-
credentialReferenceId: 'your-credential-id-from-ui', // Credential ID from Step 2
35-
transport: {
36-
type: MCPTransportType.streamableHttp,
37-
},
38-
});
39-
```
4031

41-
### Option 2: Define Environment-Based Credentials
32+
### Nango Store
33+
**Common use case**: OAuth tokens from OAuth2.1/PKCE flows, complex OAuth flows, integrating with external services (Slack, GitHub, Google, etc.), when extra headers are needed, etc. Credentials configured through Visual Builder.
34+
35+
- Managed through Nango (self-hosted or cloud)
36+
- Supports various authentication methods: OAuth2.0, API keys, basic auth, and more
37+
- Can provide additional metadata headers passed to MCP servers
38+
- Requires OAuth setup through Visual Builder
39+
40+
### Keychain Store
41+
**Common use case**: Locally stored OAuth tokens from OAuth2.1/PKCE flows. Credentials configured through Visual Builder.
42+
43+
- Credentials stored in native OS keychain (macOS Keychain Access, Windows Credential Manager, Linux Secret Service)
44+
- Mainly used locally for development with OAuth services
45+
- Requires OAuth setup through Visual Builder
4246

43-
For development workflows, you can define credentials that reference environment variables:
47+
## Creating and Using Credentials
48+
49+
### Basic Setup Example
4450

4551
```typescript
46-
import { mcpTool, credential, MCPTransportType } from '@inkeep/agents-sdk';
47-
import { CredentialStoreType } from '@inkeep/agents-core';
52+
import { mcpTool, credential, agent, agentGraph } from "@inkeep/agents-sdk";
53+
import { CredentialStoreType } from "@inkeep/agents-core";
4854

49-
// Define a credential that pulls from environment variables
50-
const inkeepApiKeyCredential = credential({
51-
id: 'inkeep-api-key',
52-
type: CredentialStoreType.memory,
55+
// Step 1: Create the credential
56+
const stripeCredential = credential({
57+
id: 'stripe-credential',
58+
type: CredentialStoreType.memory, // Memory store
5359
credentialStoreId: 'memory-default',
5460
retrievalParams: {
55-
key: 'INKEEP_API_KEY',
61+
key: 'STRIPE_API_KEY', // STRIPE_API_KEY=your-stripe-key should be set as an environment variable (.env file)
5662
},
5763
});
5864

59-
// Reference the credential object
60-
const inkeepAnalyticsTool = mcpTool({
61-
id: 'inkeep-analytics',
62-
name: 'inkeep_analytics',
63-
description: 'Get the latest stats from the Inkeep Analytics dashboard',
64-
serverUrl: 'https://analytics.inkeep.com/mcp',
65-
credentialReference: inkeepApiKeyCredential, // Reference to credential object
66-
transport: {
67-
type: MCPTransportType.streamableHttp,
68-
},
65+
// Step 2: Use credential in MCP tool
66+
const stripeTool = mcpTool({
67+
id: 'stripe-tool',
68+
name: 'Stripe Tool',
69+
description: 'Access Stripe payment services',
70+
serverUrl: 'https://mcp.stripe.com',
71+
credential: stripeCredential, // Reference the credential
72+
});
73+
74+
// Step 3: Add tool to agent
75+
const paymentAgent = agent({
76+
id: 'payment-agent',
77+
name: 'Payment Agent',
78+
description: 'Handles payment processing',
79+
prompt: 'You handle payment-related requests using the Stripe service.',
80+
tools: () => [stripeTool],
6981
});
7082
```
7183

72-
## Best Practices
84+
## Configuration Options
7385

74-
### Production Deployments
75-
- **Use credential IDs**: Always use `credentialReferenceId` with credentials created through the UI
76-
- **Secure storage**: Credentials are encrypted and managed centrally
77-
- **Team collaboration**: Credentials can be shared across team members
86+
### Credential Configuration
7887

79-
### Development Workflows
80-
- **Environment credentials**: Use `credentialReference` with environment-based credentials
81-
- **Local development**: Define credentials in your `environments/*.env.ts` files
82-
- **CI/CD integration**: Environment variables can be managed by your deployment pipeline
88+
| Parameter | Type | Required | Description |
89+
|-----------|------|----------|-------------|
90+
| `id` | string | Yes | Unique identifier for the credential |
91+
| `type` | CredentialStoreType | Yes | Type of credential store (memory, nango, or keychain) |
92+
| `credentialStoreId` | string | Yes | Identifier for the specific credential store instance |
93+
| `retrievalParams` | object | Yes | Parameters for retrieving the credential from the store. See below for more details. |
8394

84-
### Environment Integration
95+
### Retrieval Parameters by Store Type
96+
97+
**Memory store** credentials:
98+
``` typescript
99+
retrievalParams: {
100+
"key": "<environment-variable-name>", // where <environment-variable-name> is the name of the environment variable that contains the credential value
101+
}
102+
```
103+
104+
**Nango store** credentials (created through the Visual Builder - OAuth2.1/PKCE flow or Bearer authentication flow):
105+
``` typescript
106+
// OAuth2.1/PKCE flow
107+
retrievalParams: {
108+
"connectionId": "oauth_token_<toolId>", // where <toolId> is the id of the MCP tool the credential is associated with
109+
"providerConfigKey": "oauth_token_<toolId>",
110+
"provider": "private-api-bearer",
111+
"authMode": "API_KEY"
112+
}
113+
114+
// Bearer authentication
115+
retrievalParams: {
116+
"connectionId": "<id-given-to-bearer-api-key>", // where <id-given-to-bearer-api-key> is the id given to the bearer api key created in through the Visual Builder
117+
"providerConfigKey": "<id-given-to-bearer-api-key>",
118+
"provider": "private-api-bearer",
119+
"authMode": "API_KEY"
120+
}
121+
```
122+
123+
**Keychain store** credentials (created through the Visual Builder - OAuth2.1/PKCE flow):
124+
``` typescript
125+
retrievalParams: {
126+
"key": "oauth_token_<toolId>" // where <toolId> is the id of the MCP tool the credential is associated with
127+
}
128+
```
129+
130+
### Environment-aware Credentials
85131

86132
You can also define credentials in your environment files:
87133

88-
```typescript
89-
// environments/development.env.ts
90-
import { registerEnvironmentSettings } from '@inkeep/agents-sdk';
91-
import { CredentialStoreType } from '@inkeep/agents-core';
92-
93-
export const development = registerEnvironmentSettings({
94-
credentials: {
95-
'openai-dev': {
96-
id: 'openai-dev',
97-
type: CredentialStoreType.memory,
98-
credentialStoreId: 'memory-default',
99-
retrievalParams: {
100-
key: 'OPENAI_API_KEY_DEV',
134+
<Tabs>
135+
<Tab title="Environment File">
136+
```bash title=".env"
137+
STRIPE_API_KEY_DEV=sk-stripe-dev-key...
138+
STRIPE_API_KEY_PROD=sk-stripe-prod-key...
139+
```
140+
</Tab>
141+
142+
<Tab title="Development Config">
143+
```typescript title="environments/development.ts"
144+
import { registerEnvironmentSettings } from '@inkeep/agents-sdk';
145+
import { CredentialStoreType } from '@inkeep/agents-core';
146+
147+
export const development = registerEnvironmentSettings({
148+
credentials: {
149+
'stripe_api_key': {
150+
id: 'stripe-api-key',
151+
type: CredentialStoreType.memory,
152+
credentialStoreId: 'memory-default',
153+
retrievalParams: {
154+
key: 'STRIPE_API_KEY_DEV',
155+
},
156+
}
101157
},
102-
},
103-
'inkeep-api-dev': {
104-
id: 'inkeep-api-dev',
105-
type: CredentialStoreType.memory,
106-
credentialStoreId: 'memory-default',
107-
retrievalParams: {
108-
key: 'INKEEP_API_KEY_DEV',
158+
});
159+
```
160+
</Tab>
161+
162+
<Tab title="Production Config">
163+
```typescript title="environments/production.ts"
164+
import { registerEnvironmentSettings } from '@inkeep/agents-sdk';
165+
import { CredentialStoreType } from '@inkeep/agents-core';
166+
167+
export const production = registerEnvironmentSettings({
168+
credentials: {
169+
'stripe_api_key': {
170+
id: 'stripe-api-key',
171+
type: CredentialStoreType.memory,
172+
credentialStoreId: 'memory-default',
173+
retrievalParams: {
174+
key: 'STRIPE_API_KEY_PROD',
175+
},
176+
}
109177
},
110-
},
111-
},
112-
});
113-
```
178+
});
179+
```
180+
</Tab>
181+
182+
<Tab title="Index File">
183+
```typescript title="environments/index.ts"
184+
import { createEnvironmentSettings } from '@inkeep/agents-sdk';
185+
import { development } from './development.env';
186+
import { production } from './production.env';
187+
188+
export const envSettings = createEnvironmentSettings({
189+
development,
190+
production,
191+
});
192+
```
193+
</Tab>
194+
</Tabs>
114195

115196
Then reference them in your tools:
116197

117-
```typescript
118-
// tools/analytics-tool.ts
119-
import { mcpTool, MCPTransportType } from '@inkeep/agents-sdk';
120-
121-
export const analyticsTool = mcpTool({
122-
id: 'analytics',
123-
name: 'analytics_tool',
124-
description: 'Access analytics data',
125-
serverUrl: 'https://analytics.example.com/mcp',
126-
credentialReferenceId: 'inkeep-api-dev', // References environment credential
127-
transport: {
128-
type: MCPTransportType.streamableHttp,
129-
},
198+
199+
```typescript title="tools/stripe-tool.ts"
200+
import { mcpTool } from "@inkeep/agents-sdk";
201+
import { envSettings } from "../environments";
202+
203+
export const stripeTool = mcpTool({
204+
id: 'stripe-tool',
205+
name: 'Stripe',
206+
serverUrl: 'https://mcp.stripe.com/mcp',
207+
credential: envSettings.getEnvironmentSetting('stripe_api_key'),
130208
});
131209
```
210+
211+
This pattern is useful if you want to keep track of different credentials for different environments. When you push your project using the [Inkeep CLI](/typescript-sdk/cli-reference#inkeep-push) `inkeep push` command with the `--env` flag, the credentials will be loaded from the appropriate environment file. For example, if you run `inkeep push --env development`, the credentials will be loaded from the `environments/development.env.ts` file.

0 commit comments

Comments
 (0)