What are API Sources?
API Sources transform REST APIs into dynamic MCP tools. Instead of manually implementing API clients, you configure the base URL and authentication, and Craft Agents creates a flexible tool that handles requests automatically.How it Works
- Configure API endpoint and auth method
- System generates a flexible
api_{name}tool - Agent calls tool with
{ path, method, params } - Authentication headers injected automatically
- Response returned (or saved if binary/large)
Authentication Types
API sources support six authentication methods:Bearer Token
Most common for API keys and access tokens:"Bearer"(default) →Authorization: Bearer token123"Token"→Authorization: Token token123""(empty) →Authorization: token123(no prefix)
Header Authentication
Custom header for API keys:Multi-Header Authentication
APIs requiring multiple auth headers (e.g., Datadog):Query Parameter Authentication
API key in URL query string:Basic Authentication
Username and password:OAuth (Google, Slack, Microsoft)
Full OAuth 2.0 flows with automatic token refresh. See OAuth Providers section below.OAuth Providers
Three providers have built-in OAuth support with automatic token refresh:Google APIs
Supports Gmail, Calendar, Drive, Docs, Sheets:Google Service Scopes
Google Service Scopes
| Service | Scopes |
|---|---|
gmail | gmail.readonly, gmail.send, gmail.modify |
calendar | calendar.readonly, calendar.events |
drive | drive.readonly, drive.file |
docs | documents.readonly |
sheets | spreadsheets.readonly |
Slack APIs
Supports Slack Web API with user authentication:Slack Service Scopes
Slack Service Scopes
Uses
Override with custom scopes:
user_scope for user authentication (not bot):| Service | User Scopes |
|---|---|
messaging | chat:write, channels:read, groups:read |
channels | channels:history, channels:read |
users | users:read, users:read.email |
files | files:read, files:write |
full | All of the above |
Microsoft APIs
Supports Microsoft Graph (Outlook, OneDrive, Calendar, Teams):Microsoft Service Scopes
Microsoft Service Scopes
| Service | Scopes |
|---|---|
outlook | Mail.Read, Mail.Send |
microsoft-calendar | Calendars.Read, Calendars.ReadWrite |
onedrive | Files.Read, Files.ReadWrite |
teams | Team.ReadBasic.All, Chat.Read |
sharepoint | Sites.Read.All |
Dynamic API Tool
Each API source generates a single flexible tool:Request Processing
Token Refresh Flow
OAuth sources automatically refresh tokens before expiry:Refresh logic is deduplicated - concurrent requests reuse the same refresh promise to prevent token rotation conflicts (important for Microsoft).
Bridge MCP Server
For Codex and Copilot sessions, API sources run in a subprocess (Bridge MCP Server). Since it can’t access encrypted credentials directly, a credential cache is used:Main Process Writes Cache
When source is enabled, decrypt credential and write to:Permissions:
0600 (owner read/write only)Bridge Reads on Each Request
Bridge MCP Server reads fresh credential from cache file before each API call
Creating API Sources
Default Headers
Include headers with every request (e.g., beta features):Binary File Handling
API responses are automatically checked for binary content:- Images: PNG, JPEG, GIF, WebP, SVG
- Documents: PDF, DOCX, XLSX, PPTX
- Archives: ZIP, TAR, GZ
- Media: MP3, MP4, WAV
Files larger than 100MB are rejected before download to prevent OOM errors.
Large Response Handling
Text responses over 25KB are automatically handled:- Save to file: Response saved to
session/downloads/ - Summarize: If
summarizecallback provided, AI generates summary - Return path: Agent receives file path instead of full content
Best Practices
Use OAuth for user data
Use OAuth for user data
OAuth tokens are scoped to the authenticated user. Use bearer tokens only for service accounts or public data.
Document API endpoints in guide.md
Document API endpoints in guide.md
List common endpoints, query patterns, and response structures:
Set meaningful _intent
Set meaningful _intent
Always include
_intent parameter to explain what you’re trying to accomplish. This helps with debugging and logging.Handle rate limits gracefully
Handle rate limits gracefully
Check API documentation for rate limits and implement backoff strategies in your agents.
Next Steps
MCP Servers
Learn about full-featured MCP servers with tools and resources
Local Files
Connect to local filesystems and Git repositories