@withone/mcp 1.1.1 → 1.2.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 +1 -1
- package/build/helpers.js +100 -0
- package/build/index.js +13 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -130,7 +130,7 @@ ONE_KNOWLEDGE_AGENT=true
|
|
|
130
130
|
| `ONE_PERMISSIONS` | `read` \| `write` \| `admin` | `admin` | Filter actions by HTTP method. `read` = GET only, `write` = GET/POST/PUT/PATCH, `admin` = all methods |
|
|
131
131
|
| `ONE_CONNECTION_KEYS` | `*` or comma-separated keys | `*` | Restrict visible connections and platforms to specific connection keys |
|
|
132
132
|
| `ONE_ACTION_IDS` | `*` or comma-separated IDs | `*` | Restrict visible and executable actions to specific action IDs |
|
|
133
|
-
| `ONE_KNOWLEDGE_AGENT` | `true` \| `false` | `false` | Remove the `execute_one_action` tool entirely, forcing knowledge-only mode |
|
|
133
|
+
| `ONE_KNOWLEDGE_AGENT` | `true` \| `false` | `false` | Remove the `execute_one_action` tool entirely, forcing knowledge-only mode. `get_one_action_knowledge` responses additionally include an Integration Code Guide (passthrough URL, `x-one-*` headers, `ONE_SECRET` / `ONE_{PLATFORM}_CONNECTION_KEY` env vars, backend-only placement) for writing application code |
|
|
134
134
|
|
|
135
135
|
All defaults preserve current behavior. If no access control env vars are set, the server starts with full access and all tools available.
|
|
136
136
|
|
package/build/helpers.js
CHANGED
|
@@ -96,6 +96,106 @@ BODY: {{BODY}}
|
|
|
96
96
|
|
|
97
97
|
QUERY PARAMS: {{QUERY_PARAMS}}`;
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Uppercases a platform id into an env-var segment, collapsing every
|
|
101
|
+
* non-alphanumeric run to a single underscore ("ship-station" -> "SHIP_STATION").
|
|
102
|
+
* @param platform - The kebab-case platform identifier
|
|
103
|
+
* @returns The env-var-safe uppercase segment
|
|
104
|
+
*/
|
|
105
|
+
export function platformEnvSegment(platform) {
|
|
106
|
+
return platform
|
|
107
|
+
.toUpperCase()
|
|
108
|
+
.split(/[^A-Z0-9]+/)
|
|
109
|
+
.filter(Boolean)
|
|
110
|
+
.join("_");
|
|
111
|
+
}
|
|
112
|
+
const CUSTOM_ACTION_NOTE = `
|
|
113
|
+
- This is a custom action: ALSO include "connectionKey" (the same value as the
|
|
114
|
+
x-one-connection-key header) as a field in the JSON body for non-GET requests.`;
|
|
115
|
+
/**
|
|
116
|
+
* Builds the knowledge-mode response: the action's knowledge document followed
|
|
117
|
+
* by the Integration Code Guide for writing application code against the One
|
|
118
|
+
* Passthrough API (env vars, backend-only placement, headers, deployment).
|
|
119
|
+
* Used only when ONE_KNOWLEDGE_AGENT is enabled; normal mode keeps
|
|
120
|
+
* buildActionKnowledgeWithGuidance.
|
|
121
|
+
* @param details - Full action details from the knowledge endpoint
|
|
122
|
+
* @param platform - The kebab-case platform identifier from the tool args
|
|
123
|
+
* @param baseUrl - The One API base URL (e.g. https://api.withone.ai)
|
|
124
|
+
* @returns The knowledge text with the appended Integration Code Guide
|
|
125
|
+
*/
|
|
126
|
+
export function buildKnowledgeModeGuidance(details, platform, baseUrl) {
|
|
127
|
+
const apiBase = baseUrl.replace(/\/$/, "");
|
|
128
|
+
const knowledge = details.knowledge || "No knowledge was found";
|
|
129
|
+
const method = (details.method || "").toUpperCase();
|
|
130
|
+
const path = details.path.startsWith("/") ? details.path : `/${details.path}`;
|
|
131
|
+
const connEnv = `ONE_${platformEnvSegment(platform)}_CONNECTION_KEY`;
|
|
132
|
+
const customNote = details.tags?.includes("custom") ? CUSTOM_ACTION_NOTE : "";
|
|
133
|
+
return `${knowledge}
|
|
134
|
+
|
|
135
|
+
================================================================
|
|
136
|
+
INTEGRATION CODE GUIDE — using this action in an application
|
|
137
|
+
================================================================
|
|
138
|
+
You are in knowledge mode: this action cannot be executed here. Use this
|
|
139
|
+
guide to write integration code in the user's project.
|
|
140
|
+
|
|
141
|
+
## 1. Where this code must live
|
|
142
|
+
Server-side only — an API route, edge function, or backend handler
|
|
143
|
+
(e.g. Supabase Edge Function, Next.js route handler, Express route).
|
|
144
|
+
NEVER call this API from browser/client code and NEVER hardcode secret
|
|
145
|
+
values in source — read them from environment variables.
|
|
146
|
+
|
|
147
|
+
## 2. The request
|
|
148
|
+
All calls go through the One Passthrough API. Do NOT call the third-party
|
|
149
|
+
API URL from the documentation above directly.
|
|
150
|
+
|
|
151
|
+
URL: ${apiBase}/v1/passthrough${path}
|
|
152
|
+
Method: ${method}
|
|
153
|
+
Headers:
|
|
154
|
+
- x-one-secret: the value of the ONE_SECRET env var
|
|
155
|
+
- x-one-connection-key: the value of the ${connEnv} env var
|
|
156
|
+
- x-one-action-id: ${details._id}
|
|
157
|
+
- Content-Type: application/json
|
|
158
|
+
|
|
159
|
+
The URL is the One base plus the action path ONLY:
|
|
160
|
+
✅ ${apiBase}/v1/passthrough${path}
|
|
161
|
+
❌ ${apiBase}/v1/passthrough/https://some-vendor-api.com${path}
|
|
162
|
+
|
|
163
|
+
## 3. Parameter placement
|
|
164
|
+
Per the documentation above:
|
|
165
|
+
- Path variables (placeholders like {{userId}} in the path) → substitute
|
|
166
|
+
real values into the URL path; never send them in the body.
|
|
167
|
+
- Query parameters → the URL query string, not the body.
|
|
168
|
+
- Body fields → the JSON request body (POST/PUT/PATCH only).${customNote}
|
|
169
|
+
|
|
170
|
+
## 4. Environment variables & deployment
|
|
171
|
+
The code will not work until the user sets these in their hosting
|
|
172
|
+
platform's secrets manager (Supabase secrets, Vercel/Netlify environment
|
|
173
|
+
settings, or the project's env settings — never committed to code):
|
|
174
|
+
- ONE_SECRET → their One API key (from the One dashboard)
|
|
175
|
+
- ${connEnv} → the connection key for ${platform} (from list_one_integrations)
|
|
176
|
+
When you deliver the code, explicitly tell the user to set both.
|
|
177
|
+
|
|
178
|
+
## 5. Code generation rules
|
|
179
|
+
- Use TypeScript unless the user asked for another language.
|
|
180
|
+
- Include the complete input/output structure from the documentation
|
|
181
|
+
above (required/optional fields, types) in the implementation.
|
|
182
|
+
- Handle errors: on a non-2xx response, read the response body and
|
|
183
|
+
surface a useful message.
|
|
184
|
+
- Minimal example:
|
|
185
|
+
|
|
186
|
+
\`\`\`typescript
|
|
187
|
+
const response = await fetch("${apiBase}/v1/passthrough${path}", {
|
|
188
|
+
method: "${method}",
|
|
189
|
+
headers: {
|
|
190
|
+
"x-one-secret": process.env.ONE_SECRET,
|
|
191
|
+
"x-one-connection-key": process.env.${connEnv},
|
|
192
|
+
"x-one-action-id": "${details._id}",
|
|
193
|
+
"Content-Type": "application/json",
|
|
194
|
+
},
|
|
195
|
+
// body: JSON.stringify(...) — only for non-GET requests
|
|
196
|
+
});
|
|
197
|
+
\`\`\``;
|
|
198
|
+
}
|
|
99
199
|
/**
|
|
100
200
|
* Replaces path variables in a template string with actual values.
|
|
101
201
|
* Path variables can be in either format: {variableName} or {{variableName}} and will be replaced with corresponding values.
|
package/build/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
|
11
11
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
12
12
|
import { ErrorCode, McpError, } from '@modelcontextprotocol/sdk/types.js';
|
|
13
13
|
import { OneClient } from './client.js';
|
|
14
|
-
import { buildActionKnowledgeWithGuidance, filterByPermissions, isMethodAllowed, isActionAllowed, computeConnectionAccess, } from './helpers.js';
|
|
14
|
+
import { buildActionKnowledgeWithGuidance, buildKnowledgeModeGuidance, filterByPermissions, isMethodAllowed, isActionAllowed, computeConnectionAccess, } from './helpers.js';
|
|
15
15
|
import { listOneIntegrationsToolConfig, searchOnePlatformActionsToolConfig, getOneActionKnowledgeToolConfig, executeOneActionToolConfig } from './schemas.js';
|
|
16
16
|
const SERVER_NAME = "one-mcp-server";
|
|
17
17
|
const SERVER_VERSION = "1.0.0";
|
|
@@ -211,6 +211,18 @@ async function handleGetActionKnowledge(args) {
|
|
|
211
211
|
throw new McpError(ErrorCode.InvalidRequest, `Platform "${args.platform}" has no allowed connections`);
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
|
+
if (ONE_KNOWLEDGE_AGENT) {
|
|
215
|
+
const details = await oneClient.getActionDetails(actionId);
|
|
216
|
+
const knowledgeWithGuide = buildKnowledgeModeGuidance(details, args.platform, oneClient.getBaseUrl());
|
|
217
|
+
return {
|
|
218
|
+
content: [
|
|
219
|
+
{
|
|
220
|
+
type: "text",
|
|
221
|
+
text: knowledgeWithGuide,
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
};
|
|
225
|
+
}
|
|
214
226
|
const { knowledge, method } = await oneClient.getActionKnowledge(actionId);
|
|
215
227
|
const knowledgeWithGuidance = buildActionKnowledgeWithGuidance(knowledge, method, oneClient.getBaseUrl(), args.platform, actionId);
|
|
216
228
|
return {
|