Skip to main content

Sema4AI Model Context Protocol (MCP)

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sema4ai_mcp-0.0.3.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sema4ai_mcp-0.0.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file sema4ai_mcp-0.0.3.tar.gz.

File metadata

  • Download URL: sema4ai_mcp-0.0.3.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for sema4ai_mcp-0.0.3.tar.gz
Algorithm Hash digest
SHA256 0491c4b6d36791fe4f45fc5b617b0346bc69bfe57b71eba42b2eea5e7c0d9983
MD5 6d48060744557a6d64f8a6e951abf558
BLAKE2b-256 9552b8a7c42f1d5cecf195bb39827c09bb3bd08368f77711ff84430f53b5dc56

See more details on using hashes here.

File details

Details for the file sema4ai_mcp-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: sema4ai_mcp-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for sema4ai_mcp-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 010ed44f2698ffc7eea34acadf21538d2f28056dd045b768999a7a76cbde83b0
MD5 a1640235683bbdd10109845d235e4eb1
BLAKE2b-256 4fc4f2a4219d6675c6589d79992621f8fa292ed1ee662992a6ee5c3b29714acc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page