Python SDK for converting documentation into MCP-compliant API endpoints for AI assistants
Project description
doc2mcp Python SDK
Python client library for the doc2mcp service that converts documentation into MCP-compliant API endpoints.
Installation
pip install doc2mcp
Quick Start
Authentication
First, authenticate with your doc2mcp server:
from doc2mcp import login
# Login to your doc2mcp instance
login("https://your-doc2mcp-instance.com")
Upload Documentation
from doc2mcp import Doc2MCPClient
# Initialize authenticated client
client = Doc2MCPClient()
# Upload documentation files
project = client.upload_documents(
name="My API Documentation",
files=["./docs/api.md", "./docs/guide.md", "./README.md"],
description="Complete API documentation for my project"
)
print(f"Project created: {project.name}")
print(f"MCP Endpoint: {project.mcp_endpoint}")
print(f"API Token: {project.api_token}")
Search Documents
# Search your documentation
results = client.search(
project_slug=project.slug,
query="authentication setup",
api_token=project.api_token,
limit=5
)
for result in results.results:
print(f"Score: {result.score}")
print(f"Content: {result.content[:200]}...")
List Projects
# Get all your projects
projects = client.get_projects()
for project in projects:
print(f"{project.name} ({project.status}) - {project.file_count} files")
CLI Usage
The SDK includes a command-line interface:
Authentication
# Login
doc2mcp login --server https://your-instance.com
# Check login status
doc2mcp whoami
# Logout
doc2mcp logout
Project Management
# Upload documentation
doc2mcp upload --name "My Docs" --description "API documentation" ./docs/
# List projects
doc2mcp list
# Search in a project
doc2mcp search my-project-slug "authentication"
# Delete a project
doc2mcp delete my-project-slug
API Reference
Client Class
from doc2mcp import Doc2MCPClient
client = Doc2MCPClient(
base_url="https://your-instance.com", # Optional, uses authenticated server
api_key="your-api-key" # Optional, uses stored credentials
)
Methods
upload_documents(name, files, description="")
Upload documentation files and create a new project.
Parameters:
name(str): Project namefiles(List[str]): List of file paths to uploaddescription(str, optional): Project description
Returns: Project object with endpoint details
get_projects()
Get all projects for the authenticated user.
Returns: List of Project objects
get_project(project_id)
Get a specific project by ID.
Parameters:
project_id(int): Project ID
Returns: Project object
delete_project(project_id)
Delete a project and its MCP endpoint.
Parameters:
project_id(int): Project ID to delete
Returns: Boolean indicating success
search(project_slug, query, api_token, limit=10)
Search documents in a project using the MCP endpoint.
Parameters:
project_slug(str): Project slugquery(str): Search queryapi_token(str): API token for authenticationlimit(int, optional): Maximum number of results
Returns: SearchResult object with matching documents
Data Models
Project
@dataclass
class Project:
id: int
name: str
slug: str
description: str
status: str # 'processing', 'ready', 'error'
file_count: int
mcp_endpoint: str
api_token: str
created_at: str
SearchResult
@dataclass
class SearchResult:
results: List[SearchResultItem]
total: int
query: str
@dataclass
class SearchResultItem:
content: str
score: float
metadata: dict
Error Handling
from doc2mcp.exceptions import (
Doc2MCPError,
ProjectNotFoundError,
UploadError,
APIError
)
try:
project = client.upload_documents(
name="My Docs",
files=["./nonexistent.md"]
)
except UploadError as e:
print(f"Upload failed: {e}")
except APIError as e:
print(f"API error: {e}")
Configuration
The SDK stores configuration in ~/.config/doc2mcp/config.json:
{
"server_url": "https://your-instance.com",
"api_key": "your-api-key"
}
Contributing
- Clone the repository
- Install in development mode:
pip install -e . - Run tests:
pytest tests/ - Follow the contribution guidelines in CONTRIBUTING.md
Author
Created by Yacine Zahidi (@ell-hol)
License
MIT License - see LICENSE file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file doc2mcp-0.0.45.tar.gz.
File metadata
- Download URL: doc2mcp-0.0.45.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf748776362cc2ead7db1b3cf68ee1eb3356c44d9b4ea2053befb8ea8b69287e
|
|
| MD5 |
a77c3a011817000c6bb9e95a5272da3a
|
|
| BLAKE2b-256 |
293482fe19715045b0f37f6e33703d8e2d5b5f8608242310e575c4e0d45c5603
|
File details
Details for the file doc2mcp-0.0.45-py3-none-any.whl.
File metadata
- Download URL: doc2mcp-0.0.45-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c30e203c75472257a0992c58ae68edf7ac52f15982ef2cc87f65945be4a254b
|
|
| MD5 |
257572d8a675b0f2f74e947c62bb34a1
|
|
| BLAKE2b-256 |
0459c60ce7d7de128804032d34fa47612a12edf16d841d263a6101728842ada6
|