Skip to main content
Glama
aac6fef

Mathematica MCP Server

by aac6fef

close_mathematica_session

Terminates a specific Wolfram Language session and releases associated resources to free up system memory and kernel licenses. Use to close active sessions efficiently.

Instructions

Terminates a specific Wolfram Language session and releases all associated resources.

It is good practice to call this tool when you are finished with a session to free up system memory and kernel licenses. Once a session is closed, its ID can no longer be used.

Args: session_id: The unique identifier of the session you wish to close. This must be an ID from an active, open session. Example: 'bee-sloth-auk-mole'.

Returns: A confirmation message indicating that the session was successfully closed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'close_mathematica_session' tool. Decorated with @mcp.tool() which also handles registration in the FastMCP server. Validates session ID using AnimalIdGenerator, terminates the WolframLanguageSession, removes it from the global sessions dictionary, and returns a success message or raises an error.
    @mcp.tool()
    def close_mathematica_session(session_id: str) -> str:
        """
        Terminates a specific Wolfram Language session and releases all associated resources.
    
        It is good practice to call this tool when you are finished with a session
        to free up system memory and kernel licenses. Once a session is closed, its
        ID can no longer be used.
    
        Args:
            session_id: The unique identifier of the session you wish to close.
                        This must be an ID from an active, open session.
                        Example: 'bee-sloth-auk-mole'.
    
        Returns:
            A confirmation message indicating that the session was successfully closed.
        """
        # 验证 session_id
        if not id_generator.verify(session_id):
            raise ValueError("Invalid session ID.")
    
        session = sessions.get(session_id)
        if not session:
            raise ValueError(f"Session with ID '{session_id}' not found or already closed.")
    
        try:
            # 终止会话并从字典中移除
            session.terminate()
            del sessions[session_id]
            return f"Session '{session_id}' closed successfully."
        except Exception as e:
            raise RuntimeError(f"An error occurred while closing session '{session_id}': {e}") from e
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and does well: it discloses that the tool is destructive (terminates session, releases resources), has irreversible effects (ID becomes unusable), and has system-level implications (frees memory and licenses). It doesn't mention error handling or permissions, but covers core behavioral traits adequately for a termination tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Perfectly structured and front-loaded: first sentence states core purpose, second provides usage guidance, third explains irreversible consequence. The Args/Returns sections are clearly labeled but not part of the description text being scored. Every sentence earns its place with no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 1 parameter with 0% schema coverage and no annotations, the description provides complete context: purpose, usage guidelines, parameter semantics, and behavioral implications. The output schema exists, so return values needn't be explained in the description. This is comprehensive for a simple termination tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate fully. It provides detailed semantics for the single parameter: explains what session_id represents ('unique identifier of the session'), constraints ('must be an ID from an active, open session'), and includes a concrete example ('bee-sloth-auk-mole'). This adds significant value beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Terminates a specific Wolfram Language session') and resource ('releases all associated resources'), distinguishing it from sibling tools like create_mathematica_session (creates) and execute_mathematica_code (runs code). The verb 'terminates' is precise and unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states when to use ('when you are finished with a session to free up system memory and kernel licenses') and when not to use ('Once a session is closed, its ID can no longer be used'), with clear alternatives implied (use create_mathematica_session for new sessions or execute_mathematica_code for active ones). The guidance is practical and actionable.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aac6fef/mathematica_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server