Skip to content

tenets.mcp Package

Tenets MCP Server - Model Context Protocol integration.

This module provides an MCP server that exposes tenets functionality to AI coding assistants like Cursor, Claude Desktop, Windsurf, and custom agents.

The MCP server wraps the existing tenets core library, providing: - Tools: Actions AI can invoke (distill, rank, examine, etc.) - Resources: Data AI can read (context history, session state, analysis) - Prompts: Reusable interaction templates

Usage

Start the MCP server (stdio transport for local IDE integration)

$ tenets-mcp

Or with specific transport

$ tenets-mcp --transport stdio # Local (default) $ tenets-mcp --transport sse # Server-Sent Events $ tenets-mcp --transport http # Streamable HTTP

Programmatic usage

from tenets.mcp import create_server server = create_server() server.run(transport="stdio")

Configuration

MCP settings can be configured in .tenets.yml:

YAML
mcp:
  enabled: true
  transports:
    stdio: true
    sse: false
    http: false

Example IDE Configuration (Claude Desktop):

JSON
{
  "mcpServers": {
    "tenets": {
      "command": "tenets-mcp",
      "args": []
    }
  }
}

Attributes

MCP_VERSIONmodule-attribute

Python
MCP_VERSION = __version__

Classes

TenetsMCP

Python
TenetsMCP(name: str = 'tenets', config: Optional[TenetsConfig] = None, project_path: Optional[Path] = None)

Tenets MCP Server.

Wraps the tenets core library and exposes functionality via MCP protocol. This class manages the FastMCP server instance and handles lifecycle.

ATTRIBUTEDESCRIPTION
name

Server name for MCP identification.

tenets

Underlying Tenets instance for actual functionality.

TYPE:Tenets

config

Configuration for the MCP server.

TYPE:Tenets

Example

from tenets.mcp import TenetsMCP server = TenetsMCP() server.run(transport="stdio")

Initialize the MCP server.

PARAMETERDESCRIPTION
name

Server name shown to MCP clients.

TYPE:strDEFAULT:'tenets'

config

Optional TenetsConfig. If not provided, uses defaults.

TYPE:Optional[TenetsConfig]DEFAULT:None

project_path

Optional project root path. Defaults to cwd.

TYPE:Optional[Path]DEFAULT:None

Attributes

nameinstance-attribute
Python
name = name
tenetsproperty
Python
tenets: Tenets

Lazy-load the Tenets instance.

Functions

get_instanceclassmethod
Python
get_instance(name: str = 'tenets', config: Optional['TenetsConfig'] = None, project_path: Optional[Path] = None) -> 'TenetsMCP'

Get or create a singleton MCP server instance.

Using a singleton preserves warm state (loaded analyzers, cached results) across multiple tool invocations, significantly improving response times.

PARAMETERDESCRIPTION
name

Server name shown to MCP clients.

TYPE:strDEFAULT:'tenets'

config

Optional TenetsConfig. Only used on first creation.

TYPE:Optional['TenetsConfig']DEFAULT:None

project_path

Optional project root path. Only used on first creation.

TYPE:Optional[Path]DEFAULT:None

RETURNSDESCRIPTION
'TenetsMCP'

The singleton TenetsMCP instance.

reset_instanceclassmethod
Python
reset_instance() -> None

Reset the singleton instance.

Primarily for testing. Clears the cached instance so the next call to get_instance() creates a fresh server.

warm_components
Python
warm_components() -> None

Pre-warm critical components for faster tool responses.

Triggers lazy loading of expensive components (analyzers, rankers) before the first tool invocation, reducing initial response latency.

This is called automatically on server start when using run().

run
Python
run(transport: Literal['stdio', 'sse', 'http'] = 'stdio', host: str = '127.0.0.1', port: int = 8080, warm: bool = True) -> None

Run the MCP server with the specified transport.

PARAMETERDESCRIPTION
transport

Transport type - stdio (local), sse, or http (remote).

TYPE:Literal['stdio', 'sse', 'http']DEFAULT:'stdio'

host

Host for network transports (sse, http).

TYPE:strDEFAULT:'127.0.0.1'

port

Port for network transports (sse, http).

TYPE:intDEFAULT:8080

warm

Whether to pre-warm components before starting (default True).

TYPE:boolDEFAULT:True

Functions

create_server

Python
create_server(name: str = 'tenets', config: Optional[TenetsConfig] = None, use_singleton: bool = True) -> TenetsMCP

Create or get a Tenets MCP server instance.

Factory function for creating MCP servers. This is the recommended way to instantiate the server for programmatic use.

By default, uses a singleton pattern to preserve warm state across invocations, significantly improving response times for repeated calls.

PARAMETERDESCRIPTION
name

Server name shown to MCP clients.

TYPE:strDEFAULT:'tenets'

config

Optional TenetsConfig for customization.

TYPE:Optional[TenetsConfig]DEFAULT:None

use_singleton

If True (default), returns a shared singleton instance. Set to False to create a fresh instance each time.

TYPE:boolDEFAULT:True

RETURNSDESCRIPTION
TenetsMCP

Configured TenetsMCP instance ready to run.

Example

from tenets.mcp import create_server server = create_server() server.run(transport="stdio")

main

Python
main() -> None

CLI entry point for tenets-mcp server.

Parses command-line arguments and starts the MCP server with the specified transport configuration.

Modules