Skip to main content

ivcap-lambda: Python SDK for Lambda-Style IVCAP Services

Package renamed: ivcap-ai-tool has been renamed to ivcap-lambda to reflect that the library is useful for any lambda-style IVCAP service, not just AI agent tools. A compatibility shim is published under the old name — existing apps will continue to work but will see a DeprecationWarning prompting migration.

Coverity Scan Build Status

ivcap-lambda is a Python library that turns a plain Python function into a set of IVCAP-compatible HTTP endpoints and/or a spec-compliant MCP (Model Context Protocol) server, from the same tool code. It sits on top of ivcap-service and FastAPI, and handles:

  • Registering tool functions as HTTP endpoints (with async "try-later" semantics)
  • Job execution in threads, result caching, and graceful shutdown
  • Event/progress reporting back to the IVCAP platform
  • Automatic tool-description endpoints (for AI agents) and an optional MCP endpoint (built on the official mcp Python SDK)

📖 Full documentation: https://ivcap-works.github.io/ivcap-ai-tool-sdk-python/

🚀 New to the library? Depending on your goal:


Installation

pip install ivcap-lambda

# To also expose tools as an MCP server:
pip install ivcap-lambda[mcp]

Minimal Example

from pydantic import BaseModel, Field
from ivcap_service import Service, getLogger, with_schema
from ivcap_lambda import start_lambda_server, ivcap_lambda, ToolOptions, logging_init

logging_init()
logger = getLogger("my-service")

service = Service(
    name="My IVCAP Service",
    description="A minimal example service.",
    contact={"name": "Alice", "email": "alice@example.com"},
    license={"name": "MIT", "url": "https://opensource.org/licenses/MIT"},
)


@with_schema("urn:example:schema:echo.request.1")
class EchoRequest(BaseModel):
    message: str = Field(..., description="The message to echo back.")


@with_schema("urn:example:schema:echo.1")
class EchoResult(BaseModel):
    echo: str = Field(..., description="The echoed message.")


@ivcap_lambda("/", opts=ToolOptions(tags=["Echo"]))
def echo(req: EchoRequest) -> EchoResult:
    """Echo a message

    Returns the message passed in the request unchanged.
    """
    return EchoResult(echo=req.message)


if __name__ == "__main__":
    start_lambda_server(service)

Run and test it:

python my_service.py --port 8090
curl -X POST http://localhost:8090/ -H "content-type: application/json" -d '{"message": "Hello, IVCAP!"}'

# Or, with the mcp extra installed, run the exact same tool as an MCP server instead:
python my_service.py --with-mcp-stdio

For everything else — defining tools, ToolOptions, JobContext, progress reporting, artifacts, MCP, project layout, deployment, Docker — see the full documentation and AGENTS.md. This README intentionally stays limited to installation/quick-start plus notes for anyone working on ivcap-lambda itself (below), to avoid duplicating content that's already maintained in the docs site.


Migration from ivcap-ai-tool

Old (deprecated) New
pip install ivcap-ai-tool pip install ivcap-lambda
from ivcap_ai_tool import ... from ivcap_lambda import ...
@ivcap_ai_tool(...) @ivcap_lambda(...)

The old ivcap-ai-tool package is a compatibility shim that re-exports everything from ivcap-lambda. It will emit a DeprecationWarning at import time. No code changes beyond the import are required.


Contributing / Developing ivcap-lambda Itself

The sections below are for anyone extending, fixing, or releasing this library — not for consumers of the package. See also CONTRIBUTING.md, DESIGN.md (internal architecture), and CONDUCT.md.

Repository Layout

ivcap-ai-tool/
├── ivcap_lambda/    # the library itself
├── compat/          # ivcap-ai-tool deprecation shim (old package name)
├── docs/            # MkDocs documentation site (docs/docs) + build output (docs/site)
├── examples/        # runnable example services (test-tool, test-mcp)
├── tests/           # unit tests
├── AGENTS.md        # user-facing reference for AI coding agents
├── DESIGN.md        # internal architecture & design rationale
└── pyproject.toml

Setup, Tests & Checks

poetry install
make test    # pytest --cov=ivcap_lambda
make check   # test + ruff check + mypy

Running the Example Services

cd examples/test-tool && poetry install && make run   # REST example
cd examples/test-mcp  && poetry install && make run   # MCP example (HTTP)
cd examples/test-mcp  && make run-mcp-stdio            # MCP example (stdio)

Building & Serving the Documentation Site

make docs-serve   # live-reload at a random local port
make docs-build   # build static site into docs/site

Releasing

Versioning/publishing is driven by semantic_release config in pyproject.toml on main. make build / make publish wrap poetry build/poetry publish.

License

Licensed under the BSD-style license in LICENSE. See AUTHORS.md for contributors.

Metadata

Release files for ivcap-lambda 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ivcap-lambda 0.8.1
File Size Uploaded
ivcap_lambda-0.8.1.tar.gz 23.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ivcap-lambda 0.8.1
File Interpreter ABI Platform
ivcap_lambda-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 52.1 kB

Release files / ivcap_lambda-0.8.1.tar.gz

Download URL ivcap_lambda-0.8.1.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
975aaa6640dcb55eec9cea0b08019a1f6048623f2f872b03f52c8697935eab1a
BLAKE2b-256 checksum
How to use checksums
440bb10e9c75125f9b28b9feb95974d62f0074998b17bc94f85fefd5bd98b7f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.5 Darwin/24.6.0

Release files / ivcap_lambda-0.8.1-py3-none-any.whl

Download URL ivcap_lambda-0.8.1-py3-none-any.whl
Size 28.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f8940e040f9e0d7a58b2d83b68cc2ba78914217662df1a1ac2b00a713dd7907
BLAKE2b-256 checksum
How to use checksums
92179f6424579e346030994eda71b547d1f5ec303f5d503b1a5ead93a57b2872
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.5 Darwin/24.6.0

Release history Release notifications | RSS feed

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

This release

0.8.1 This release

2 release files

0.7.25

2 release files

0.7.22

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page