datacloud-code-mcp
A Salesforce Data Cloud MCP server using Cloudflare Code Mode, enabling agents to discover and execute Data Cloud operations via a two-step search-and-execute loop with JavaScript code.
README
Data Cloud Code MCP
A Salesforce Data Cloud (Data360) MCP server using the Cloudflare Code Mode pattern: two tools (search + execute), each taking a JavaScript async arrow function, with a fixed ~1k-token tool footprint regardless of API surface size.
How It Works
Instead of exposing hundreds of endpoint-level tools, this server gives agents a stable two-step loop:
search— agent writes JavaScript to filter the OpenAPI spec and discover Data Cloud endpoints.execute— agent writes JavaScript that callssalesforce.request()to make authenticated API requests.
Both tools run user code in a node:vm sandbox with restricted globals. The full OpenAPI spec never enters the model context — the agent explores it programmatically through search().
What's Covered
~185 Data Cloud operations across 25 API families:
| Family | Examples |
|---|---|
| Query | SQL query (v1/v2/v3), profile, insights, data graphs |
| DMO/DLO | CRUD for Data Model Objects and Data Lake Objects |
| Mappings | DMO field mappings, bulk mappings, standard mappings |
| Data Streams | List, create, update, delete, trigger runs |
| Connectors | List types, metadata, CRUD connections, test |
| Calculated Insights | CRUD, run, validate, enable/disable |
| Segments | CRUD, publish, members, overlap analysis |
| Identity Resolution | CRUD rulesets, publish, run, match history |
| Activations | CRUD activations + targets, sync, history |
| Data Transforms | CRUD, run, validate, schedule |
| Semantic Data Models | Models, objects, dimensions, measurements, metrics, relationships, query |
| Data Spaces | CRUD spaces, member management |
| DataKits | List, manifest, deploy, undeploy, component status |
| GDPR | Right-to-access, bulk read, erasure requests |
| Search Indexes | CRUD, hybrid full-text query |
| Eventing | Single and batch a360 event publish |
| Data Actions | CRUD actions + targets |
Quick Start
npm install
npm run build
npm test # 27 tests across 5 suites
Auth Options
Option 1: Direct access token (same env vars as d360-mcp-server)
CDP_ACCESS_TOKEN=<token> CDP_INSTANCE_URL=<url> npm run dev
Option 2: OAuth client credentials
CDP_CLIENT_ID=<id> CDP_CLIENT_SECRET=<secret> CDP_LOGIN_URL=https://login.salesforce.com npm run dev
Option 3: OAuth web flow
- Set
SALESFORCE_OAUTH_CLIENT_ID,SALESFORCE_OAUTH_CLIENT_SECRET,SALESFORCE_OAUTH_REDIRECT_URIin.env. - Start server:
npm run dev - Open
/oauth/start?user_id=defaultand complete login.
Option 4: Seed token from CLI
npm run seed:token # reads sf CLI auth or env vars
TOKEN_STORE_PATH=./data/tokens.integration.json \
TOKEN_ENCRYPTION_KEY_BASE64='<from seed>' npm run dev
Run Server
PORT=3000 HOST=127.0.0.1 npm run dev
curl -sS http://127.0.0.1:3000/healthz
Smoke Test
MCP_URL=http://127.0.0.1:3000/mcp USER_ID=default npm run smoke:mcp
Example Calls
Search: find endpoints by tag
{
"name": "search",
"arguments": {
"code": "async () => {\n const results = [];\n for (const [path, methods] of Object.entries(spec.paths)) {\n for (const [method, op] of Object.entries(methods)) {\n if (op.tags?.some(t => t.toLowerCase().includes('segment'))) {\n results.push({ method: method.toUpperCase(), path, summary: op.summary });\n }\n }\n }\n return results;\n}"
}
}
Search: inspect an endpoint schema
{
"name": "search",
"arguments": {
"code": "async () => {\n const op = spec.paths['/services/data/v64.0/ssot/query-sql']?.post;\n return { summary: op?.summary, requestBody: op?.requestBody };\n}"
}
}
Execute: run a SQL query
{
"name": "execute",
"arguments": {
"code": "async () => {\n return await salesforce.request({\n method: 'POST',\n path: '/services/data/v64.0/ssot/query-sql',\n body: { sql: 'SELECT FirstName__c FROM UnifiedIndividual__dlm LIMIT 5' }\n });\n}"
}
}
Execute: chain multiple calls
{
"name": "execute",
"arguments": {
"code": "async () => {\n const list = await salesforce.request({ method: 'GET', path: '/services/data/v64.0/ssot/segments' });\n const first = list.body?.data?.[0];\n if (!first) return { message: 'No segments' };\n return await salesforce.request({ method: 'GET', path: '/services/data/v64.0/ssot/segments/' + first.id });\n}"
}
}
MCP Client Integration
{
"mcpServers": {
"datacloud-code-mcp": {
"transport": "streamable_http",
"url": "http://127.0.0.1:3000/mcp",
"headers": { "x-user-id": "default" }
}
}
}
Safety Model
- Mutating methods (
POST,PATCH,PUT,DELETE) blocked unlessALLOW_WRITES=true. salesforce.request()only allows outbound HTTP to the authenticated instance's hostname +*.salesforce.com+*.force.com.- Sensitive headers/body keys are redacted in tool output.
- User code runs in a
node:vmsandbox with norequire,process,global, or filesystem access. - Sandbox enforces
SANDBOX_TIMEOUT_MS(default 15s) to prevent runaway execution.
Deploy to Heroku
heroku create
heroku config:set TOKEN_ENCRYPTION_KEY_BASE64=$(node -e "console.log(require('crypto').randomBytes(32).toString('base64'))")
heroku config:set ALLOW_WRITES=false
heroku config:set CDP_ACCESS_TOKEN=<token> CDP_INSTANCE_URL=<url>
git push heroku main
Then point your MCP client at https://<app>.herokuapp.com/mcp.
Configuration
See .env.example for all available environment variables.
Project Layout
src/
index.ts HTTP server + MCP session management
mcp-server.ts Tool registration (search, execute, auth_status)
config.ts Zod-parsed environment config
types.ts Shared TypeScript interfaces
logger.ts Pino logger
auth/
oauth-service.ts Salesforce OAuth web flow + token exchange
auth-modes.ts Strategy resolver (direct/client-cred/password/oauth)
token-store.ts AES-256-GCM encrypted token persistence
schema/
datacloud-schema-service.ts Catalog loader, merger, $ref resolver
catalog.ts OpenAPI → PlatformOperation parser
spec-processor.ts $ref resolution + spec processing (Cloudflare pattern)
bundled-spec.ts Resolve bundled YAML paths
data360-api.bundled.yaml Base OpenAPI spec (~35 endpoints)
d360-extras.yaml Extended endpoints (~150 more operations)
sandbox/
runner.ts node:vm sandbox executor
sf-client.ts salesforce.request() injectable client
safe-fetch.ts Hostname-allow-listed fetch wrapper
truncate.ts Response truncation
execute/
datacloud-executor.ts Legacy structured executor (kept for reference)
redaction.ts Body/header redaction helpers
http-policy.ts Retry + read-cache helpers
safety/
write-confirmation.ts HMAC write tokens (used by legacy executor)
search/
search-index.ts BM25 search index (kept for potential reuse)
utils/
crypto.ts AES-256-GCM encrypt/decrypt
headers.ts Header value resolver
tests/ Vitest test suites
scripts/ Smoke test + token seed scripts
docs/ Reference docs (Data Cloud guide, Postman)
References
- Cloudflare Code Mode MCP — the pattern this server follows
- Cloudflare MCP repo — reference implementation
- Anthropic: Introducing advanced tool use
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。