MCP Server¶
lcp.mcp_server ¶
MCP server that exposes LCP manifest data to AI agents.
DEFAULT_MAX_RESPONSE_BYTES
module-attribute
¶
Default byte budget for any list-returning tool payload (spec D6).
Calibrated against polars 1.42.1: DataFrame's 159 member summaries alone are ~30 KB, so heavy classes are expected to truncate; 25 KB is ~6k tokens.
LCPIndex ¶
In-memory index of LCP document for fast lookups.
Source code in src/lcp/mcp_server.py
resolve_id ¶
Resolve a possibly-aliased id to (canonical_id, symbol).
Returns (None, None) when the id matches neither a canonical
entry nor a known alias.
Source code in src/lcp/mcp_server.py
MultiLibraryIndex ¶
Registry of loaded LCPIndex instances for the MCP server.
Holds one :class:LCPIndex per loaded library plus the source it was
resolved from. There is deliberately no implicit default library:
with one library loaded :meth:resolve returns it for a None
argument, with several it returns an ambiguous_library error
(spec D7).
Source code in src/lcp/mcp_server.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
add ¶
Register (or replace) a library index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Library name used as the lookup key. |
required |
index
|
LCPIndex
|
Built index for the library's manifest. |
required |
source
|
str
|
Where the manifest came from ( |
'scan'
|
Source code in src/lcp/mcp_server.py
get ¶
source ¶
names ¶
resolve ¶
Resolve a tool's library argument to an index (spec D7).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
library
|
str | None
|
Explicit library name, or None. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
|
LCPIndex | None
|
on failure — the error dict follows the D5 shape. |
Source code in src/lcp/mcp_server.py
list_libraries ¶
Return summary info for all loaded libraries.
Source code in src/lcp/mcp_server.py
LCPServer
dataclass
¶
A configured LCP MCP server plus direct access to its internals.
Attributes:
| Name | Type | Description |
|---|---|---|
mcp |
FastMCP
|
The underlying FastMCP server (use :meth: |
index |
MultiLibraryIndex
|
The registry of loaded library indexes. |
tools |
dict[str, Callable[..., Any]]
|
Raw tool callables by name, for in-process invocation (tests, preload) without the MCP protocol. |
Source code in src/lcp/mcp_server.py
load_lcp_document ¶
Load and validate an LCP document from a file.
Supports both plain .lcp.json files and gzip-compressed
.lcp.json.gz files, detected transparently by file extension.
Source code in src/lcp/mcp_server.py
resolve_library_document ¶
resolve_library_document(name: str, cache_dir: Path = _DEFAULT_CACHE_DIR, no_cache: bool = False, registry_url: str | None = None, version: str | None = None, scan_mode: str = 'subprocess', scan_python: str | None = None, scan_timeout: float = DEFAULT_SCAN_TIMEOUT) -> tuple[ScanResult, str]
Resolve an LCP document for name using the standard resolution order.
Resolution order
- Local cache (~/.lcp/cache/{name}/{version}.lcp.json)
- Live scan (subprocess by default; see scan_mode)
- Registry (HTTP GET from registry_url if provided)
- Error
Registry manifests are fetched from the path
{registry_url}/manifests/python/{name}/{version}.lcp.json.
When the installed version is unknown, "latest" is used as the
version segment so registries can expose a canonical latest entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Python package name to resolve. |
required |
cache_dir
|
Path
|
Cache root directory (default: ~/.lcp/cache/). |
_DEFAULT_CACHE_DIR
|
no_cache
|
bool
|
Skip cache read/write entirely. |
False
|
registry_url
|
str | None
|
Optional base URL of an LCP registry to try when local
scanning fails. The default official registry is at
|
None
|
version
|
str | None
|
Optional exact version to prefer; overrides the installed version for cache lookup and registry fetch. A live scan always returns the installed version regardless. |
None
|
scan_mode
|
str
|
|
'subprocess'
|
scan_python
|
str | None
|
Interpreter whose environment the live scan reads (default: this process's interpreter). This is how packages installed in a different venv get resolved. |
None
|
scan_timeout
|
float
|
Seconds before a subprocess scan is killed. |
DEFAULT_SCAN_TIMEOUT
|
Returns:
| Type | Description |
|---|---|
ScanResult
|
Tuple of (ScanResult, source) where source is |
str
|
|
tuple[ScanResult, str]
|
|
tuple[ScanResult, str]
|
list, because the diagnostic is not persisted in the manifest. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the package cannot be resolved via any available source (cache, scan, or registry). |
Source code in src/lcp/mcp_server.py
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
create_universal_server ¶
create_universal_server(name: str = 'lcp-universal', cache_dir: Path | str | None = None, no_cache: bool = False, registry_url: str | None = None, expose: list[str] | None = None, preload: list[str] | None = None, max_response_bytes: int = DEFAULT_MAX_RESPONSE_BYTES, scan_mode: str = 'subprocess', scan_python: str | None = None, scan_timeout: float = DEFAULT_SCAN_TIMEOUT) -> LCPServer
Create a universal MCP server that resolves any installed Python library.
The server exposes exactly four tools — resolve_library, search,
get_symbol, get_overview — and carries adoption-focused
instructions so agents verify APIs before writing code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Server name shown to MCP clients. |
'lcp-universal'
|
cache_dir
|
Path | str | None
|
Root directory for cached manifests (default ~/.lcp/cache/). |
None
|
no_cache
|
bool
|
Disable reading from and writing to the cache. |
False
|
registry_url
|
str | None
|
Optional LCP registry URL used when local scanning fails. |
None
|
expose
|
list[str] | None
|
Optional allow-list of package names resolve_library may load. |
None
|
preload
|
list[str] | None
|
Package names to resolve eagerly at startup. |
None
|
max_response_bytes
|
int
|
Byte budget for list-returning tool responses. |
DEFAULT_MAX_RESPONSE_BYTES
|
scan_mode
|
str
|
Live-scan strategy: |
'subprocess'
|
scan_python
|
str | None
|
Interpreter whose environment live scans read (default: the interpreter running the server). |
None
|
scan_timeout
|
float
|
Seconds before a subprocess scan is killed. |
DEFAULT_SCAN_TIMEOUT
|
Returns:
| Name | Type | Description |
|---|---|---|
An |
LCPServer
|
class: |
LCPServer
|
index, and the raw tool callables. |
Source code in src/lcp/mcp_server.py
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 | |
create_server ¶
Create an MCP server pre-loaded with one LCP manifest.
.. deprecated::
lcp serve / create_server are deprecated; use
lcp serve-all --expose <package> / :func:create_universal_server.
This wrapper builds the same universal server with the manifest
pre-loaded and resolution locked to its library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest_path
|
str | Path
|
Path to the |
required |
name
|
str | None
|
Server name (default: |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Configured |
LCPServer
|
class: |
Source code in src/lcp/mcp_server.py
run_server ¶
Create and run a (deprecated) single-manifest MCP server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest_path
|
str | Path
|
Path to the |
required |
name
|
str | None
|
Server name (default: |
None
|
Source code in src/lcp/mcp_server.py
run_universal_server ¶
run_universal_server(name: str = 'lcp-universal', cache_dir: Path | str | None = None, no_cache: bool = False, registry_url: str | None = None, expose: list[str] | None = None, preload: list[str] | None = None, max_response_bytes: int = DEFAULT_MAX_RESPONSE_BYTES, scan_mode: str = 'subprocess', scan_python: str | None = None, scan_timeout: float = DEFAULT_SCAN_TIMEOUT) -> None
Create and run a universal MCP server that resolves any installed Python library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Server name (default: lcp-universal). |
'lcp-universal'
|
cache_dir
|
Path | str | None
|
Root directory for cached manifests (default: ~/.lcp/cache/). |
None
|
no_cache
|
bool
|
Disable reading from and writing to the cache. |
False
|
registry_url
|
str | None
|
Optional base URL of an LCP registry used as a fallback when local scanning fails. |
None
|
expose
|
list[str] | None
|
Optional allow-list of package names for |
None
|
preload
|
list[str] | None
|
Package names to resolve eagerly at startup. |
None
|
max_response_bytes
|
int
|
Byte budget for list-returning tool responses. |
DEFAULT_MAX_RESPONSE_BYTES
|
scan_mode
|
str
|
Live-scan strategy: |
'subprocess'
|
scan_python
|
str | None
|
Interpreter whose environment live scans read (default: the interpreter running the server). |
None
|
scan_timeout
|
float
|
Seconds before a subprocess scan is killed. |
DEFAULT_SCAN_TIMEOUT
|