Python SDK for generating Library Context Protocol (LCP) files from Python packages
Project description
Library Context Protocol
Documentation: https://zazza123.github.io/lcp
lcp (Library Context Protocol) is primarly a protocol designed to solve the problem of AI agents not having access to up-to-date library documentation, which leads to hallucinations and inaccurate code generation. The LCP SDK provides tools to scan Python packages, extract API information, and generate LCP-compliant JSON manifests. It also includes features for analyzing documentation coverage and generating missing docstrings using AI.
Installation
pip install lcp
Features
- Scans installed Python packages using
inspectandastmodules - Generates LCP v1 compliant JSON files
- Extracts functions, classes, methods, attributes, and constants
- Parses docstrings for summaries and descriptions
- Extracts type hints from function signatures
- Validates output against LCP JSON schema
- Documentation coverage analysis with JSON/Markdown reports
- Version diff to detect deprecated symbols across releases
- AI-powered docstring generation via OpenAI and Anthropic (
lcp[ai]) - Both CLI and Python API interfaces
- MCP server for AI agent integration
Usage
CLI
# Scan a package and output LCP JSON
lcp scan requests -o requests.lcp.json
# Include private symbols
lcp scan mypackage --include-private
# Skip validation
lcp scan mypackage --no-validate
# Start an MCP server for a library manifest
lcp serve requests.lcp.json
Python API
from lcp import scan
# Scan a package
lcp_doc = scan("requests")
# Save to file
lcp_doc.to_file("requests.lcp.json")
# Get as dict
data = lcp_doc.to_dict()
# Include private symbols
lcp_doc = scan("mypackage", include_private=True)
Documentation Coverage
Analyze documentation completeness of a package to identify missing docstrings.
CLI
# Generate coverage report (JSON)
lcp coverage requests -o coverage.json
# Generate coverage report (Markdown)
lcp coverage requests -o coverage.md --format markdown
# Generate both LCP manifest and coverage report in one scan
lcp scan requests -o requests.lcp.json --coverage coverage.json
Python API
from lcp import generate_coverage
# Generate coverage report
report = generate_coverage("requests")
# Check coverage percentage
print(f"Coverage: {report.summary.coverage_percent}%")
print(f"Documented: {report.summary.documented}/{report.summary.total_symbols}")
# List undocumented symbols
for symbol in report.undocumented:
print(f" - {symbol.module}:{symbol.entity} ({symbol.kind})")
# Save report
report.to_file("coverage.json") # JSON format
report.to_file("coverage.md") # Markdown format
Version Diff
Compare two LCP manifests to detect symbols that were removed between versions and automatically generate deprecation entries.
CLI
# Compare two versions and print the diff report
lcp diff v1.lcp.json v2.lcp.json
# Save the diff report to a file
lcp diff v1.lcp.json v2.lcp.json -o diff.json
# Automatically update the new manifest with deprecation entries
lcp diff v1.lcp.json v2.lcp.json --update
Python API
from lcp import diff_documents, load_lcp_document, update_document
# Load two versions
old = load_lcp_document("v1.lcp.json")
new = load_lcp_document("v2.lcp.json")
# Compare
result = diff_documents(old, new)
print(f"Removed: {len(result.removed)}, Added: {len(result.added)}")
for sid, dep in result.deprecated.items():
print(f" {sid}: deprecated in {dep.deprecated_in}")
# Merge deprecations into the new document
updated = update_document(new, result)
updated.to_file("v2.lcp.json")
MCP Server
The SDK includes an MCP (Model Context Protocol) server that exposes LCP manifest data to AI agents. This allows agents to explore library APIs and generate accurate code.
Starting the Server
# Start MCP server for a library
lcp serve requests.lcp.json
# With custom server name
lcp serve numpy.lcp.json --name numpy-docs
MCP Client Configuration
Add to your MCP client configuration (e.g., Claude Desktop):
{
"mcpServers": {
"requests-api": {
"command": "lcp",
"args": ["serve", "/path/to/requests.lcp.json"]
}
}
}
Available MCP Tools
| Tool | Description |
|---|---|
get_manifest |
Get library metadata (name, version, language) |
list_modules |
List all modules in the library |
list_symbols |
Browse symbols with optional filtering by module or kind |
get_symbol |
Get full details for a specific symbol |
search_symbols |
Find symbols by text search |
get_class_members |
Get all methods and attributes of a class |
Programmatic Usage
from lcp.mcp_server import create_server, run_server
# Create and customize server
server = create_server("path/to/manifest.lcp.json", name="my-server")
# Or run directly
run_server("path/to/manifest.lcp.json")
AI Documentation Generation
Automatically generate missing docstrings using LLM providers (OpenAI, Anthropic). Requires the optional ai extra:
pip install lcp[ai]
CLI
# Generate coverage report first
lcp coverage mypackage -o coverage.json
# Generate docstrings (dry-run to preview)
lcp docgen coverage.json --provider openai --dry-run
# Generate docstrings for real
lcp docgen coverage.json --provider openai
# Use Anthropic
lcp docgen coverage.json --provider anthropic --model claude-sonnet-4-20250514
# Filter by symbol kind
lcp docgen coverage.json --kinds class,function,method
# Provide a guiding description
lcp docgen coverage.json --description "A web framework for building REST APIs"
# Use OpenAI reasoning models (o1, o3)
lcp docgen coverage.json --provider openai --model o3 --reasoning
Python API
from lcp.ai import DocGenAgent, DocGenConfig, OpenAIProvider
# Create provider and agent
provider = OpenAIProvider(model="gpt-4o")
config = DocGenConfig(kinds=["class", "function"], dry_run=True)
agent = DocGenAgent(provider=provider, config=config)
# Run on a coverage JSON file
result = agent.run("coverage.json")
# Or pass a dict directly
result = agent.run(coverage_dict)
# Inspect results
print(f"Updated: {result.symbols_updated}")
print(f"Tokens: {result.total_usage.input_tokens} in / {result.total_usage.output_tokens} out")
for r in result.results:
print(f" {r.symbol_id}: {r.status}")
Claude Code Plugin
The SDK ships a ready-to-install Claude Code plugin in plugin/lcp/. It packages lcp serve-all as an MCP server so Claude Code can resolve any pip-installed Python library on demand — no per-project configuration required.
Prerequisites
pip install lcp
Installation
claude plugin install plugin/lcp
Once installed, Claude Code automatically starts the LCP MCP server on session start. The lcp-universal skill instructs the agent to call resolve_library("package") before writing code that depends on an external library.
Optional: configure a registry
During or after installation you can configure one or more registry URLs (comma-separated) for teams that host pre-built manifests for private packages:
claude plugin config lcp registries https://raw.githubusercontent.com/your-org/lcp-registry/main
Shortcuts
| Shortcut | Action |
|---|---|
/lcp:resolve <package> |
Resolve a library and summarise its public API |
/lcp:scan <package> |
Scan a package and display module/symbol overview |
License
MIT
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 lcp-1.0.1.tar.gz.
File metadata
- Download URL: lcp-1.0.1.tar.gz
- Upload date:
- Size: 538.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e23d4aabade8b535590d24ef9696e8719c453bea22adc0b53ea40ee32e66f8ed
|
|
| MD5 |
e2289a8097b72f99f5058426442726de
|
|
| BLAKE2b-256 |
26a66a62508bcd18e06e74d08ad101dacd1e9a451797b789e667ed3dc74c4056
|
Provenance
The following attestation bundles were made for lcp-1.0.1.tar.gz:
Publisher:
publish.yml on zazza123/lcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lcp-1.0.1.tar.gz -
Subject digest:
e23d4aabade8b535590d24ef9696e8719c453bea22adc0b53ea40ee32e66f8ed - Sigstore transparency entry: 1766677316
- Sigstore integration time:
-
Permalink:
zazza123/lcp@79017a924e9f37b63d8b010b3bb4ba5d17963b1b -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/zazza123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@79017a924e9f37b63d8b010b3bb4ba5d17963b1b -
Trigger Event:
release
-
Statement type:
File details
Details for the file lcp-1.0.1-py3-none-any.whl.
File metadata
- Download URL: lcp-1.0.1-py3-none-any.whl
- Upload date:
- Size: 58.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9a72333a01c2c9a84321760e0e36072d33635075503cf641b110aab463ce798
|
|
| MD5 |
d226c500790a74e1d08ab38928df2141
|
|
| BLAKE2b-256 |
33c9efa296487809f402542b6b99acda50022147034cea9d9205b45f684f5a87
|
Provenance
The following attestation bundles were made for lcp-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on zazza123/lcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lcp-1.0.1-py3-none-any.whl -
Subject digest:
f9a72333a01c2c9a84321760e0e36072d33635075503cf641b110aab463ce798 - Sigstore transparency entry: 1766677408
- Sigstore integration time:
-
Permalink:
zazza123/lcp@79017a924e9f37b63d8b010b3bb4ba5d17963b1b -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/zazza123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@79017a924e9f37b63d8b010b3bb4ba5d17963b1b -
Trigger Event:
release
-
Statement type: