Skip to content

mcp_server

Class info

Classes

Name Children Inherits
MCPServerBase
llmling_agent.models.mcp_server
Base model for MCP server configuration.
PoolServerConfig
llmling_agent.models.mcp_server
Configuration for pool-based MCP server.
    SSEMCPServer
    llmling_agent.models.mcp_server
    MCP server using Server-Sent Events transport.
      StdioMCPServer
      llmling_agent.models.mcp_server
      MCP server started via stdio.

        🛈 DocStrings

        MCPServerBase

        Bases: BaseModel

        Base model for MCP server configuration.

        Source code in src/llmling_agent/models/mcp_server.py
         9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30
        31
        32
        class MCPServerBase(BaseModel):
            """Base model for MCP server configuration."""
        
            type: str
            """Type discriminator for MCP server configurations."""
        
            name: str | None = None
            """Optional name for referencing the server."""
        
            enabled: bool = True
            """Whether this server is currently enabled."""
        
            environment: dict[str, str] | None = None
            """Environment variables to pass to the server process."""
        
            model_config = ConfigDict(use_attribute_docstrings=True, extra="forbid")
        
            def get_env_vars(self) -> dict[str, str]:
                """Get environment variables for the server process."""
                env = os.environ.copy()
                if self.environment:
                    env.update(self.environment)
                env["PYTHONIOENCODING"] = "utf-8"
                return env
        

        enabled class-attribute instance-attribute

        enabled: bool = True
        

        Whether this server is currently enabled.

        environment class-attribute instance-attribute

        environment: dict[str, str] | None = None
        

        Environment variables to pass to the server process.

        name class-attribute instance-attribute

        name: str | None = None
        

        Optional name for referencing the server.

        type instance-attribute

        type: str
        

        Type discriminator for MCP server configurations.

        get_env_vars

        get_env_vars() -> dict[str, str]
        

        Get environment variables for the server process.

        Source code in src/llmling_agent/models/mcp_server.py
        26
        27
        28
        29
        30
        31
        32
        def get_env_vars(self) -> dict[str, str]:
            """Get environment variables for the server process."""
            env = os.environ.copy()
            if self.environment:
                env.update(self.environment)
            env["PYTHONIOENCODING"] = "utf-8"
            return env
        

        PoolServerConfig

        Bases: BaseModel

        Configuration for pool-based MCP server.

        Source code in src/llmling_agent/models/mcp_server.py
         73
         74
         75
         76
         77
         78
         79
         80
         81
         82
         83
         84
         85
         86
         87
         88
         89
         90
         91
         92
         93
         94
         95
         96
         97
         98
         99
        100
        101
        102
        103
        104
        105
        106
        107
        108
        109
        110
        111
        112
        113
        114
        115
        116
        117
        118
        119
        120
        121
        122
        123
        124
        125
        126
        127
        128
        129
        130
        131
        132
        133
        134
        class PoolServerConfig(BaseModel):
            """Configuration for pool-based MCP server."""
        
            enabled: bool = False
            """Whether this server is currently enabled."""
        
            # Resource exposure control
            serve_nodes: list[str] | bool = True
            """Which nodes to expose as tools:
            - True: All nodes
            - False: No nodes
            - list[str]: Specific node names
            """
        
            serve_prompts: list[str] | bool = True
            """Which prompts to expose:
            - True: All prompts from manifest
            - False: No prompts
            - list[str]: Specific prompt names
            """
        
            # Transport configuration
            transport: Literal["stdio", "sse"] = "stdio"
            """Transport type to use."""
        
            host: str = "localhost"
            """Host to bind server to (SSE only)."""
        
            port: int = 8000
            """Port to listen on (SSE only)."""
        
            cors_origins: list[str] = Field(default_factory=lambda: ["*"])
            """Allowed CORS origins (SSE only)."""
        
            zed_mode: bool = False
            """Enable Zed editor compatibility mode."""
        
            model_config = ConfigDict(frozen=True, use_attribute_docstrings=True, extra="forbid")
        
            def should_serve_node(self, name: str) -> bool:
                """Check if a node should be exposed."""
                match self.serve_nodes:
                    case True:
                        return True
                    case False:
                        return False
                    case list():
                        return name in self.serve_nodes
                    case _:
                        return False
        
            def should_serve_prompt(self, name: str) -> bool:
                """Check if a prompt should be exposed."""
                match self.serve_prompts:
                    case True:
                        return True
                    case False:
                        return False
                    case list():
                        return name in self.serve_prompts
                    case _:
                        return False
        

        cors_origins class-attribute instance-attribute

        cors_origins: list[str] = Field(default_factory=lambda: ['*'])
        

        Allowed CORS origins (SSE only).

        enabled class-attribute instance-attribute

        enabled: bool = False
        

        Whether this server is currently enabled.

        host class-attribute instance-attribute

        host: str = 'localhost'
        

        Host to bind server to (SSE only).

        port class-attribute instance-attribute

        port: int = 8000
        

        Port to listen on (SSE only).

        serve_nodes class-attribute instance-attribute

        serve_nodes: list[str] | bool = True
        

        Which nodes to expose as tools: - True: All nodes - False: No nodes - list[str]: Specific node names

        serve_prompts class-attribute instance-attribute

        serve_prompts: list[str] | bool = True
        

        Which prompts to expose: - True: All prompts from manifest - False: No prompts - list[str]: Specific prompt names

        transport class-attribute instance-attribute

        transport: Literal['stdio', 'sse'] = 'stdio'
        

        Transport type to use.

        zed_mode class-attribute instance-attribute

        zed_mode: bool = False
        

        Enable Zed editor compatibility mode.

        should_serve_node

        should_serve_node(name: str) -> bool
        

        Check if a node should be exposed.

        Source code in src/llmling_agent/models/mcp_server.py
        112
        113
        114
        115
        116
        117
        118
        119
        120
        121
        122
        def should_serve_node(self, name: str) -> bool:
            """Check if a node should be exposed."""
            match self.serve_nodes:
                case True:
                    return True
                case False:
                    return False
                case list():
                    return name in self.serve_nodes
                case _:
                    return False
        

        should_serve_prompt

        should_serve_prompt(name: str) -> bool
        

        Check if a prompt should be exposed.

        Source code in src/llmling_agent/models/mcp_server.py
        124
        125
        126
        127
        128
        129
        130
        131
        132
        133
        134
        def should_serve_prompt(self, name: str) -> bool:
            """Check if a prompt should be exposed."""
            match self.serve_prompts:
                case True:
                    return True
                case False:
                    return False
                case list():
                    return name in self.serve_prompts
                case _:
                    return False
        

        SSEMCPServer

        Bases: MCPServerBase

        MCP server using Server-Sent Events transport.

        Connects to a server over HTTP with SSE for real-time communication.

        Source code in src/llmling_agent/models/mcp_server.py
        57
        58
        59
        60
        61
        62
        63
        64
        65
        66
        67
        class SSEMCPServer(MCPServerBase):
            """MCP server using Server-Sent Events transport.
        
            Connects to a server over HTTP with SSE for real-time communication.
            """
        
            type: Literal["sse"] = Field("sse", init=False)
            """SSE server configuration."""
        
            url: str
            """URL of the SSE server endpoint."""
        

        type class-attribute instance-attribute

        type: Literal['sse'] = Field('sse', init=False)
        

        SSE server configuration.

        url instance-attribute

        url: str
        

        URL of the SSE server endpoint.

        StdioMCPServer

        Bases: MCPServerBase

        MCP server started via stdio.

        Uses subprocess communication through standard input/output streams.

        Source code in src/llmling_agent/models/mcp_server.py
        35
        36
        37
        38
        39
        40
        41
        42
        43
        44
        45
        46
        47
        48
        49
        50
        51
        52
        53
        54
        class StdioMCPServer(MCPServerBase):
            """MCP server started via stdio.
        
            Uses subprocess communication through standard input/output streams.
            """
        
            type: Literal["stdio"] = Field("stdio", init=False)
            """Stdio server coniguration."""
        
            command: str
            """Command to execute (e.g. "pipx", "python", "node")."""
        
            args: list[str] = Field(default_factory=list)
            """Command arguments (e.g. ["run", "some-server", "--debug"])."""
        
            @classmethod
            def from_string(cls, command: str) -> StdioMCPServer:
                """Create a MCP server from a command string."""
                cmd, args = command.split(maxsplit=1)
                return cls(command=cmd, args=args.split())
        

        args class-attribute instance-attribute

        args: list[str] = Field(default_factory=list)
        

        Command arguments (e.g. ["run", "some-server", "--debug"]).

        command instance-attribute

        command: str
        

        Command to execute (e.g. "pipx", "python", "node").

        type class-attribute instance-attribute

        type: Literal['stdio'] = Field('stdio', init=False)
        

        Stdio server coniguration.

        from_string classmethod

        from_string(command: str) -> StdioMCPServer
        

        Create a MCP server from a command string.

        Source code in src/llmling_agent/models/mcp_server.py
        50
        51
        52
        53
        54
        @classmethod
        def from_string(cls, command: str) -> StdioMCPServer:
            """Create a MCP server from a command string."""
            cmd, args = command.split(maxsplit=1)
            return cls(command=cmd, args=args.split())