Skip to main content

Sema4AI Model Context Protocol (MCP) Library

The Model Context Protocol (MCP) is a protocol that AI agents can use to take action based on the output of a conversation with an LLM. This library provides an API that allows you to implement MCP tools, resources and prompts in your Python code.

It works a bit different from other MCP implementations in that the idea is that you'll just worry about the MCP tool/resource/prompt implementation in Python, but the actual management of the connection and lifecycle of your tool/resource/prompt functions is handled by the Sema4AI Action Server.

This means that you should just focus on the MCP functions, NOT on features provided by the Sema4AI Action Server such as:

  • Running the server
  • Making logging (which is automatically setup using robocorp.log)
  • Creating your python environment (the environment is managed by a package.yaml file that's expected to be in the root of your project)
  • Handling connections
  • Providing a separate REST API to call your MCP functions (the regular REST API provided for actions in the Sema4AI Action Server may also be used to call your MCP functions)

Developing MCP functions:

Using the Sema4ai VSCode Extension, enables you to easily run your MCP functions locally and later on deploy as you'd like -- you can easily deploy your MCP server and agents to the cloud by using Sema4AI -- or just use the Sema4AI Action Server in a private cloud or locally as well.

Installation

pip install sema4ai-mcp

Usage

The package provides three main decorators:

@tool

Use the @tool decorator to define functions that can be used as tools by AI agents:

from sema4ai.mcp import tool

@tool
def assign_ticket(ticket_id: str, user_id: str) -> bool:
    """
    Assign a ticket to a user.

    Args:
        ticket_id: The ID of the ticket to assign.
        user_id: The ID of the user to assign the ticket to.

    Returns:
        True if the ticket was assigned successfully, False otherwise.
    """
    ...
    return True

The @tool decorator can also be used with the following arguments:

  • title: A human-readable title for the tool.
  • read_only_hint: If true, the tool does not modify its environment (default: False).
  • destructive_hint: If true, the tool may perform destructive updates to its environment (default: True).
  • idempotent_hint: If true, calling the tool repeatedly with the same arguments will have no additional effect on the its environment (default: False).
  • open_world_hint: If true, this tool may interact with an "open world" of external entities (default: True). If False, the tool's domain of interaction is closed. For example, the world of a web search tool is open, whereas that of a memory tool is not.

@resource

Use the @resource decorator to define functions that provide resources to the LLM:

from sema4ai.mcp import resource

@resource("tickets://{ticket_id}")
def get_ticket(ticket_id: str) -> dict[str, str]:
    """
    Get ticket information from the database.

    Args:
        ticket_id: The ID of the ticket to get information for.

    Returns:
        A dictionary containing the ticket information.
    """
    return {"id": ticket_id, "summary": "This is a test ticket"}

@prompt

Use the @prompt decorator to define functions that generate prompts.

from sema4ai.mcp import prompt

@prompt
def make_a_summary(text: str) -> str:
    """
    Provide a prompt to the LLM.
    """
    return "Please make a summary of the following text: {text}"

License

This project is licensed under the Apache License 2.0.

Metadata

Release files for sema4ai-mcp 0.0.3

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

Source distribution (sdist)

Source distribution for sema4ai-mcp 0.0.3
File Size Uploaded Provenance
sema4ai_mcp-0.0.3.tar.gz 6.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sema4ai-mcp 0.0.3
File Interpreter ABI Platform
sema4ai_mcp-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / sema4ai_mcp-0.0.3.tar.gz

Download URL sema4ai_mcp-0.0.3.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0491c4b6d36791fe4f45fc5b617b0346bc69bfe57b71eba42b2eea5e7c0d9983
BLAKE2b-256 checksum
How to use checksums
9552b8a7c42f1d5cecf195bb39827c09bb3bd08368f77711ff84430f53b5dc56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure

Release files / sema4ai_mcp-0.0.3-py3-none-any.whl

Download URL sema4ai_mcp-0.0.3-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
010ed44f2698ffc7eea34acadf21538d2f28056dd045b768999a7a76cbde83b0
BLAKE2b-256 checksum
How to use checksums
4fc4f2a4219d6675c6589d79992621f8fa292ed1ee662992a6ee5c3b29714acc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure

Security for sema4ai-mcp 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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