Skip to main content
Glama
philschmid

Code Sandbox MCP Server

by philschmid
test_integration.py2.34 kB
import pytest from fastmcp import FastMCP, Client from code_sandbox_mcp.server import mcp as code_sandbox_mcp_server import os @pytest.fixture(scope="module") def mcp_stdio_server(): """ Fixture to provide the main code_sandbox_mcp server instance for testing. """ # Set transport mode for testing os.environ["MCP_TRANSPORT_MODE"] = "stdio" yield code_sandbox_mcp_server @pytest.mark.asyncio async def test_run_python_code_integration(mcp_stdio_server: FastMCP): """ Tests the run_python_code tool using an in-memory client. """ query = "print('Hello, World!')" async with Client(mcp_stdio_server) as client: result = await client.call_tool("run_python_code", {"code": query}) assert isinstance(result.content[0].text, str) assert len(result.content[0].text) > 0 @pytest.mark.asyncio async def test_run_python_code_integration_with_error(mcp_stdio_server: FastMCP): """ Tests the run_python_code tool using an in-memory client with an error """ query = """from google.genai import genai client = genai.Client() response = client.generate_content("Hello, world!") print(response.text) """ async with Client(mcp_stdio_server) as client: result = await client.call_tool("run_python_code", {"code": query}) assert isinstance(result.content[0].text, str) assert "error" in result.content[0].text.lower() @pytest.mark.asyncio async def test_run_javascript_code_integration(mcp_stdio_server: FastMCP): """ Tests the run_javascript_code tool using an in-memory client. """ prompt = "console.log('Hello, World!');" async with Client(mcp_stdio_server) as client: result = await client.call_tool("run_javascript_code", {"code": prompt}) assert isinstance(result.content[0].text, str) @pytest.mark.asyncio async def test_run_javascript_code_integration_with_error(mcp_stdio_server: FastMCP): """ Tests the run_javascript_code tool using an in-memory client with an error """ prompt = "const x = 1 / 0; console.log(y);" async with Client(mcp_stdio_server) as client: result = await client.call_tool("run_javascript_code", {"code": prompt}) assert isinstance(result.content[0].text, str) assert "error" in result.content[0].text.lower()

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/philschmid/code-sandbox-mcp'

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