create_mathematica_session
Initiate a new, isolated Wolfram Language session for Mathematica computations. Obtain a unique session ID to manage state, execute code, and maintain independence across tasks.
Instructions
Creates and initializes a new, isolated Wolfram Language session.
This tool is the first step for any Mathematica-related task. It returns a unique, secure session identifier (e.g., 'fox-wolf-bear-lion') that you MUST use in subsequent calls to 'execute_code' and 'close_session'.
Each session is completely independent and maintains its own state (variables, function definitions, etc.).
Returns: A string containing a success message and the unique session ID. Example: "Session created successfully. Your session ID is: bee-sloth-auk-mole"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- wolfram_mathematica.py:89-112 (handler)The handler function for the 'create_mathematica_session' tool. It is decorated with @mcp.tool() for registration and implements the logic to create a new Wolfram Mathematica session using WolframLanguageSession, store it in a sessions dictionary with a unique animal ID, and return the session ID.@mcp.tool() def create_mathematica_session() -> str: """ Creates and initializes a new, isolated Wolfram Language session. This tool is the first step for any Mathematica-related task. It returns a unique, secure session identifier (e.g., 'fox-wolf-bear-lion') that you MUST use in subsequent calls to 'execute_code' and 'close_session'. Each session is completely independent and maintains its own state (variables, function definitions, etc.). Returns: A string containing a success message and the unique session ID. Example: "Session created successfully. Your session ID is: bee-sloth-auk-mole" """ session_id = id_generator.generate() try: # 创建一个新的 Wolfram Language 会话, 使用自动检测到的内核路径 session = WolframLanguageSession(KERNEL_PATH) sessions[session_id] = session return f"Session created successfully. Your session ID is: {session_id}" except Exception as e: raise RuntimeError(f"Failed to create Wolfram Language session: {e}") from e