MCP Server
Model Context Protocol server for Mapfolio - Enable AI assistants to interact with Mapfolio data
Overview
The Mapfolio MCP Server is a Model Context Protocol (MCP) server that enables AI assistants and other MCP-compatible clients to interact with Mapfolio's data and operations. It provides programmatic access to companies, projects, users, LinkedIn profiles, and administrative functions.
What is MCP?
Model Context Protocol (MCP) is an open protocol that enables AI assistants to securely access external data sources and tools. MCP servers expose capabilities through a standardized interface, allowing AI assistants to:
- Query and retrieve data
- Perform operations
- Access resources
- Integrate with external systems
Features
The Mapfolio MCP Server provides comprehensive functionality:
Company Data
- Search companies with advanced filters
- Get company details by ID
- Retrieve companies by canton and starting letter
- Get random companies for sampling
- Access company visit statistics
Project Management
- Create and manage projects
- List and filter user projects
- Update project details
- Delete projects
- Add and remove companies from projects
User Profiles
- Get user profile information
- Update profile settings
- List user projects
- Manage API keys
LinkedIn Integration
- Get LinkedIn profile data
- Search LinkedIn profiles
- Access connection information
- View profile version history
- Get LinkedIn company data
Administrative Operations
- List all users (admin only)
- Create new users (admin only)
- Manage API keys (admin only)
- Access admin dashboard statistics
Statistics
- Get aggregated company statistics
- View canton-level counts
- Access letter-based counts
- Get two-letter combination statistics
Installation
Prerequisites
- Node.js >= 20.0.0
- npm >= 10.0.0
- Access to Mapfolio Supabase instance
Setup
- Install dependencies:
cd mcp-server
npm install
- Configure environment variables:
cp .env.example .env
Edit .env and configure:
# Mapfolio API URL (defaults to https://mapfolio.app)
MAPFOLIO_API_URL=https://mapfolio.app
# Transport type: 'stdio' (default) or 'http' for remote access
MCP_TRANSPORT=stdio
# HTTP port (only used when MCP_TRANSPORT=http)
MCP_HTTP_PORT=3001
# Optional: Default authentication (can be provided via MCP context or HTTP headers)
MAPFOLIO_API_KEY=mapf_your_api_key_here
MAPFOLIO_JWT_TOKEN=your-jwt-token-here
- Build the server:
npm run build
Usage
Running the Server
Local Development (stdio transport)
The MCP server uses stdio transport by default (standard MCP protocol):
npm start
For development with auto-reload:
npm run dev
HTTP Transport (for remote access)
To run the server with HTTP transport for local testing:
MCP_TRANSPORT=http MCP_HTTP_PORT=3001 npm start
This starts an HTTP server on port 3001 that accepts JSON-RPC 2.0 requests over HTTP POST.
Vercel Deployment (Remote Access)
The MCP server is automatically available via HTTP when deployed to Vercel:
- Endpoint:
https://your-app.vercel.app/api/mcp - Protocol: JSON-RPC 2.0 over HTTP POST
- Authentication: Via
X-API-Keyheader orAuthorization: Bearer <token>header
Example request:
curl -X POST https://your-app.vercel.app/api/mcp \
-H "Content-Type: application/json" \
-H "X-API-Key: mapf_your_api_key" \
-d '{
"jsonrpc": "2.0",
"method": "tools/list",
"id": 1
}'
MCP Client Configuration
Claude Desktop
Local deployment:
{
"mcpServers": {
"mapfolio": {
"command": "node",
"args": ["/path/to/mapfolio/mcp-server/dist/index.js"],
"env": {
"MAPFOLIO_API_URL": "https://mapfolio.app",
"MAPFOLIO_API_KEY": "mapf_your_api_key_here"
}
}
}
}
Cursor
Configure via MCP settings:
- Command:
node - Args:
["/path/to/mapfolio/mcp-server/dist/index.js"] - Environment variables:
MAPFOLIO_API_URL:https://mapfolio.appMAPFOLIO_API_KEY: Your API key (optional)
Authentication
The server supports two authentication methods:
API Key Authentication
API keys are prefixed with mapf_ and can be:
- Set via
MAPFOLIO_API_KEYenvironment variable - Passed per-request via
apiKeyparameter in tool calls
JWT Token Authentication
Supabase JWT tokens can be:
- Set via
MAPFOLIO_JWT_TOKENenvironment variable - Passed per-request via
jwtTokenparameter in tool calls
Authentication Priority
- HTTP Transport: Headers (
X-API-KeyorAuthorization) take precedence - Per-request credentials (
apiKeyorjwtTokenin tool arguments) - Environment variables (
MAPFOLIO_API_KEYorMAPFOLIO_JWT_TOKEN)
HTTP Transport Authentication
When using the HTTP endpoint (/api/mcp), authentication is provided via HTTP headers:
- API Key:
X-API-Key: mapf_your_api_key - JWT Token:
Authorization: Bearer your_jwt_token
Available Tools
The server provides 30+ tools across 6 categories:
Company Tools
search_companies- Search with filtersget_company- Get company by IDget_companies_by_canton_letter- Get by canton and letterget_random_companies- Get random samplesget_company_visits- Get visit statistics
Project Tools
create_project- Create new projectlist_projects- List user projectsget_project- Get project detailsupdate_project- Update projectdelete_project- Delete projectadd_companies_to_project- Add companiesremove_companies_from_project- Remove companies
User Tools
get_user_profile- Get profileupdate_user_profile- Update profileget_user_projects- List projectsget_user_api_keys- List API keys
LinkedIn Tools
get_linkedin_profile- Get profilesearch_linkedin_profiles- Search profilesget_linkedin_connections- Get connectionsget_linkedin_profile_versions- Get version historyget_linkedin_companies- Get company data
Admin Tools (Admin Only)
list_all_users- List all userscreate_user- Create userget_user_details- Get user detailslist_api_keys- List all API keyscreate_api_key- Create API keyrevoke_api_key- Revoke API keyget_admin_stats- Get admin statistics
Statistics Tools
get_company_stats- Get aggregated statsget_canton_counts- Get canton countsget_letter_counts- Get letter countsget_two_letter_counts- Get two-letter counts
Resources
The server provides resource-based access:
mapfolio://company/{id}- Company datamapfolio://project/{id}- Project datamapfolio://user/{id}- User profilemapfolio://linkedin-profile/{id}- LinkedIn profile
Resources can include authentication via query parameters:
mapfolio://company/{id}?apiKey=mapf_...mapfolio://company/{id}?jwtToken=...
Example Usage
Search Companies
{
"tool": "search_companies",
"arguments": {
"query": "technology",
"cantons": ["ZH", "BE"],
"page": 1,
"limit": 20
}
}
Create Project
{
"tool": "create_project",
"arguments": {
"name": "Tech Companies Zurich",
"searchType": "company",
"searchQuery": "technology",
"isPublic": false
}
}
Get Company Details
{
"tool": "get_company",
"arguments": {
"companyId": "company-uuid-here"
}
}
Error Handling
All tools return errors in a consistent format:
{
"error": "Error message"
}
Common error scenarios:
- 401 Unauthorized: Invalid or missing authentication
- 403 Forbidden: Insufficient permissions
- 404 Not Found: Resource not found
- 500 Internal Server Error: Server-side error
API-Only Architecture
The MCP server uses HTTP requests to mapfolio.app instead of direct database access. This means:
- ✅ No Supabase credentials needed - Works with just API URL and API key
- ✅ Easy Vercel deployment - Deploy as serverless function
- ✅ Secure - All requests go through Mapfolio's API with authentication
- ✅ Scalable - Benefits from Mapfolio's API rate limiting and caching
Currently Available via API
- ✅ Company search and retrieval
- ✅ Company statistics (canton counts, letter counts)
- ✅ Random companies
- ✅ Company visits
Coming Soon (Requires API Endpoints)
- ⏳ Project management (create, list, update, delete)
- ⏳ User profile management
- ⏳ LinkedIn profile access
- ⏳ Admin operations
These features will return helpful error messages until the API endpoints are created.
Security Considerations
- API Keys: Store securely, never commit to version control
- JWT Tokens: Tokens expire, handle refresh appropriately
- API Rate Limiting: Respects Mapfolio's API rate limits
- HTTPS Only: Always use HTTPS for API requests
- Admin Operations: Require explicit admin authentication (when endpoints are available)
Development
Type Checking
npm run type-check
Building
npm run build
Development Mode
npm run dev
Documentation
For complete documentation, see the MCP Server README.
Support
For issues or questions:
- GitHub Issues: [mapfolio repository]
- Email: support@mapfolio.app
License
MIT