### Basic Arithmetic Example - TypeScript Source: https://github.com/bewt85/mcp-deno-sandbox/blob/main/README.md A simple TypeScript example demonstrating basic arithmetic, which works without requiring special permissions. ```typescript console.log(1 + 2); ``` -------------------------------- ### Clone and Install Dependencies - Bash Source: https://github.com/bewt85/mcp-deno-sandbox/blob/main/README.md Commands to clone the mcp-deno-sandbox repository and install its Node.js dependencies using npm. ```bash git clone https://github.com/bewt85/mcp-deno-sandbox.git cd mcp-deno-sandbox npm install ``` -------------------------------- ### Network Access Example - TypeScript Source: https://github.com/bewt85/mcp-deno-sandbox/blob/main/README.md A TypeScript example that fetches the public IP address, requiring the `--allow-net` permission to be enabled. ```typescript fetch('https://icanhazip.com').then(response => response.text()).then(ip => console.log(`Your IP is: ${ip.trim()}`)); ``` -------------------------------- ### Configure MCP Server with Deno Runtime Source: https://context7.com/bewt85/mcp-deno-sandbox/llms.txt Example JSON configuration for setting up the Deno Sandbox MCP Server using the Deno runtime directly. This shows how to specify the command, arguments, and granular file system permissions. ```json { "mcpServers": { "denoSandbox": { "command": "deno", "args": [ "run", "npm:mcp-deno-sandbox", "--allow-read=/home/user/projects", "--allow-write=/home/user/projects/output", "--deny-write=/home/user/projects/config" ] } } } ``` -------------------------------- ### Deno Runtime File System Permissions Example Source: https://github.com/bewt85/mcp-deno-sandbox/blob/main/README.md Examples demonstrating how to set file system read and write permissions for the Deno runtime. This covers both permissive full access and restricted access to specific directories. ```bash # Full file system access (read and write) --allow-read --allow-write # Limited to specific directories (read and write) --allow-read=/tmp --allow-write=/tmp ``` -------------------------------- ### Deno Runtime Network Permissions Example Source: https://github.com/bewt85/mcp-deno-sandbox/blob/main/README.md Examples illustrating how to configure network access permissions for the Deno runtime. This includes permissive access to all networks and restricted access to specific domains. ```bash # Allows all network access --allow-net # Allows network access only to specific domains --allow-net=api.github.com,example.com ``` -------------------------------- ### File System Read Example - TypeScript Source: https://github.com/bewt85/mcp-deno-sandbox/blob/main/README.md A TypeScript example that reads the content of a text file, requiring the `--allow-read` permission. ```typescript const text = Deno.readTextFileSync('/path/to/file.txt'); console.log(text); ``` -------------------------------- ### Configure MCP Server with Claude Desktop Source: https://context7.com/bewt85/mcp-deno-sandbox/llms.txt Example JSON configuration for setting up the Deno Sandbox MCP Server within Claude Desktop. This demonstrates how to specify the command, arguments, and explicit permissions for network access, file reading, and writing. ```json { "mcpServers": { "denoSandbox": { "command": "npx", "args": [ "mcp-deno-sandbox", "--allow-net=api.github.com,icanhazip.com", "--allow-read=/tmp", "--allow-write=/tmp", "--deny-read=/tmp/.ssh" ] } } } ``` -------------------------------- ### Deno Sandbox MCP Server Configuration with Node.js Source: https://github.com/bewt85/mcp-deno-sandbox/blob/main/README.md Configuration for using the mcp-deno-sandbox server with Claude Desktop when Node.js is installed. This leverages npx to automatically install and run Deno, along with specified network permissions. ```json { "mcpServers": { "denoSandbox": { "command": "npx", "args": [ "mcp-deno-sandbox", "--allow-net=icanhazip.com,example.com" ] } } } ``` -------------------------------- ### Deno Sandbox MCP Server Configuration with Deno Source: https://github.com/bewt85/mcp-deno-sandbox/blob/main/README.md Configuration for using the mcp-deno-sandbox server with Claude Desktop when Deno is installed. This specifies the command to run Deno and the necessary arguments, including network permissions. ```json { "mcpServers": { "denoSandbox": { "command": "deno", "args": [ "run", "npm:mcp-deno-sandbox", "--allow-net=icanhazip.com,example.com" ] } } } ``` -------------------------------- ### Making HTTP Requests with Permissions in Deno Source: https://context7.com/bewt85/mcp-deno-sandbox/llms.txt Demonstrates how to make HTTP GET requests in Deno, specifically requiring network permissions. It shows a basic request to an IP address service and includes error handling for permission denial. ```python import requests response = requests.get("https://icanhazip.com") print(f"Your IP: {response.text.strip()}") # Output: Your IP: 203.0.113.42 # Permission error handling try: with open("/etc/passwd", "r") as f: print(f.read()) except Exception as e: print(f"Access denied: {e}") # Error: The MCP server does not have sufficient permissions to run this code. # Required permission: --allow-read=/etc/passwd ``` -------------------------------- ### Query Deno Permissions via MCP Resource Source: https://context7.com/bewt85/mcp-deno-sandbox/llms.txt This snippet demonstrates how to query available Deno permissions and security constraints at runtime using the MCP resource endpoint. It shows an example response format and outlines how an AI can use this information to inform users about necessary permission flags for server restarts. ```typescript // MCP resource URI: permissions://deno // Access via MCP client's resource reading capability // Example response when server started with limited permissions: { "uri": "permissions://deno", "text": `Current Deno Permissions: --allow-net=icanhazip.com,example.com --allow-read=/tmp --allow-write=/tmp Deno supports the following additional permissions but these need to be configured before the server is started: --allow-read[=...] or -R[=...] --deny-read[=...] --allow-write[=...] or -W[=...] --deny-write[=...] --allow-net[=...] or -N[=...] --deny-net[=...] --allow-imports[=...] --allow-env[=...] or -E[=...] --deny-env[=...]` } // Example usage in MCP client context: // When code execution fails with permission error, AI can: // 1. Read this resource to see current permissions // 2. Inform user which permission flag needs to be added // 3. Explain that server restart is required with new permission ``` -------------------------------- ### Executing Deno Scripts Programmatically with mcp-deno-sandbox Source: https://context7.com/bewt85/mcp-deno-sandbox/llms.txt Shows how to execute Deno scripts using the `runDenoScript` function from the `mcp-deno-sandbox` library. Examples cover basic execution, file read permissions, network and write permissions, and the use of deny permissions. ```typescript import { runDenoScript } from 'mcp-deno-sandbox'; // Basic execution without permissions try { const output = await runDenoScript('console.log("Hello World");', []); console.log(output); // "Hello World\n" } catch (error) { console.error(`Execution failed: ${error.message}`); } // Execute with file read permissions const scriptCode = ` const content = Deno.readTextFileSync("/tmp/config.json"); const config = JSON.parse(content); console.log(`Port: ${config.port}`); `; try { const output = await runDenoScript(scriptCode, ['--allow-read=/tmp']); console.log(output); // "Port: 8080\n" } catch (error) { console.error(`Read failed: ${error.message}`); // Output: Error running Deno script: The MCP server does not have sufficient permissions... } // Execute with network and write permissions const fetchAndSave = ` const response = await fetch("https://api.example.com/data"); const data = await response.json(); Deno.writeTextFileSync("/tmp/result.json", JSON.stringify(data, null, 2)); console.log("Data saved successfully"); `; const permissions = [ '--allow-net=api.example.com', '--allow-write=/tmp' ]; const output = await runDenoScript(fetchAndSave, permissions); console.log(output); // "Data saved successfully\n" // Using deny permissions for fine-grained control const restrictedScript = ` const files = Array.from(Deno.readDirSync("/tmp")); console.log(`Found ${files.length} files`); `; const restrictedPerms = [ '--allow-read=/tmp', '--deny-read=/tmp/.secrets' ]; const result = await runDenoScript(restrictedScript, restrictedPerms); console.log(result); // Lists files but cannot access .secrets folder ``` -------------------------------- ### Executing Python Scripts with mcp-deno-sandbox via Pyodide Source: https://context7.com/bewt85/mcp-deno-sandbox/llms.txt Demonstrates executing Python scripts programmatically using the `runPythonScript` function from `mcp-deno-sandbox`, which leverages Pyodide. Examples include basic computations, using libraries like NumPy, network access, and a workaround for file writing using a JavaScript bridge. ```typescript import { runPythonScript } from 'mcp-deno-sandbox'; // Execute basic Python computation try { const output = await runPythonScript('print(sum([1, 2, 3, 4, 5]))', []); console.log(output); // "15\n" } catch (error) { console.error(`Execution failed: ${error.message}`); } // Execute with numpy and file system access const dataAnalysis = ` import numpy as np import json # Load data from file with open("/tmp/measurements.txt", "r") as f: values = [float(line.strip()) for line in f] # Compute statistics arr = np.array(values) stats = { "count": len(arr), "mean": float(np.mean(arr)), "median": float(np.median(arr)), "std": float(np.std(arr)) } print(json.dumps(stats, indent=2)) `; try { const permissions = ['--allow-read=/tmp']; const output = await runPythonScript(dataAnalysis, permissions); const stats = JSON.parse(output); console.log(`Mean: ${stats.mean}, Std: ${stats.std}`); } catch (error) { console.error(`Analysis failed: ${error.message}`); } // Execute with network access for API calls const apiScript = ` import requests import json response = requests.get("https://api.github.com/users/octocat") user = response.json() print(f"{user['name']} has {user['public_repos']} public repos") `; const netPerms = ['--allow-net=api.github.com']; const apiResult = await runPythonScript(apiScript, netPerms); console.log(apiResult); // "The Octocat has 8 public repos\n" // Write data using JavaScript bridge (workaround for Python file write limitation) const writeScript = ` import js import json data = {"timestamp": "2025-10-26", "value": 42} js.fs.writeFileSync("/tmp/output.json", json.dumps(data)) print("Data written via JS bridge") `; const writePerms = ['--allow-read=/tmp', '--allow-write=/tmp']; const writeOutput = await runPythonScript(writeScript, writePerms); console.log(writeOutput); // "Data written via JS bridge\n" ``` -------------------------------- ### Execute TypeScript/JavaScript Code in Deno Sandbox Source: https://context7.com/bewt85/mcp-deno-sandbox/llms.txt Demonstrates various use cases for executing TypeScript and JavaScript code within the Deno sandbox. Includes examples for basic operations, file I/O, network requests, and using npm packages, highlighting the need for explicit permissions. ```typescript // Basic arithmetic without permissions console.log(1 + 1); // Output: 2 // Reading a file with appropriate permissions (requires --allow-read=/tmp) const content = Deno.readTextFileSync("/tmp/data.txt"); console.log(content); // Output: File contents printed to stdout // Writing to a file (requires --allow-write=/tmp) Deno.writeTextFileSync("/tmp/output.txt", "Hello World"); console.log("File written successfully"); // Output: File written successfully // Fetching from the internet (requires --allow-net=api.github.com) const response = await fetch("https://api.github.com/repos/denoland/deno"); const data = await response.json(); console.log(`Deno has ${data.stargazers_count} stars`); // Output: Deno has 98765 stars // Using npm packages without additional permissions import cowsay from "npm:cowsay"; console.log(cowsay.say({text: "Hello from Deno!"})); // Output: ASCII art cow saying "Hello from Deno!" // Permission denied example (without --allow-net) try { await fetch("https://example.com"); } catch (error) { console.error("Permission denied - requires --allow-net"); } // Error: The MCP server does not have sufficient permissions to run this code. // Required permission: --allow-net=example.com ``` -------------------------------- ### Format and Debug Deno Permission Errors Source: https://context7.com/bewt85/mcp-deno-sandbox/llms.txt This TypeScript code illustrates how to handle and format Deno permission errors for user feedback using the `formatError` function from `mcp-deno-sandbox/logging`. It provides examples for read, network, and syntax errors, along with a custom logger for debugging. ```typescript import { formatError } from 'mcp-deno-sandbox/logging'; // Handle read permission error try { await runDenoScript('Deno.readTextFileSync("/etc/passwd")', []); } catch (error) { const formattedError = formatError(error); console.error(formattedError); // Output: The MCP server does not have sufficient permissions to run this code. // Required permission: NotCapable: Requires read access to "/etc/passwd" // The server needs to be restarted with --allow-read=/etc/passwd to run this code. } // Handle network permission error try { await runDenoScript('await fetch("https://api.github.com")', []); } catch (error) { const formattedError = formatError(error); console.error(formattedError); // Output: The MCP server does not have sufficient permissions to run this code. // Required permission: NotCapable: Requires net access to "api.github.com" // The server needs to be restarted with --allow-net=api.github.com to run this code. } // Handle syntax errors try { await runDenoScript('console.log("unclosed string)', []); } catch (error) { const formattedError = formatError(error); console.error(formattedError); // Output: Unclosed string literal } // Custom logger for debugging const customLogger = { log: (...args) => console.log('[DEBUG]', ...args), error: (...args) => console.error('[ERROR]', ...args) }; try { await runDenoScript(scriptCode, permissions, customLogger); } catch (error) { // Temporary directory cleanup failures will be logged via custom logger // [ERROR] Failed to remove temporary directory: /tmp/deno-sandbox-xyz123 } ``` -------------------------------- ### Execute Python Code in Deno Sandbox via Pyodide Source: https://context7.com/bewt85/mcp-deno-sandbox/llms.txt Illustrates how to execute Python code within the Deno sandbox using Pyodide. Covers basic Python operations, scientific computing with NumPy, YAML parsing, and file system interactions, emphasizing permission requirements. ```python # Basic arithmetic and printing print(2 + 2) # Output: 4 # Using numpy for array operations (no permissions needed) import numpy as np import json arr = np.array([1, 2, 3, 4, 5]) result = { "mean": float(np.mean(arr)), "sum": int(np.sum(arr)), "std": float(np.std(arr)) } print(json.dumps(result)) # Output: {"mean": 3.0, "sum": 15, "std": 1.4142135623730951} # Parsing YAML without permissions import yaml import json data = yaml.safe_load(""" --- config: host: localhost port: 8080 features: [auth, logging, metrics] """) print(json.dumps(data)) # Output: {"config": {"host": "localhost", "port": 8080, "features": ["auth", "logging", "metrics"]}} # Reading files with permissions (requires --allow-read=/tmp) with open("/tmp/data.txt", "r") as f: content = f.read() print(f"File contents: {content}") # Output: File contents: [contents of data.txt] # Writing files (requires --allow-read=/tmp and --allow-write=/tmp) import js js.fs.writeFileSync("/tmp/output.txt", "Written from Python via Pyodide") print("File written successfully") # Output: File written successfully ``` -------------------------------- ### Test with MCP Inspector - Bash Source: https://github.com/bewt85/mcp-deno-sandbox/blob/main/README.md Command to launch the MCP Inspector for testing TypeScript code within the project. ```bash npx @modelcontextprotocol/inspector ./node_modules/.bin/ts-node src/index.ts ``` -------------------------------- ### Python File Write Workaround - Python/Deno Source: https://github.com/bewt85/mcp-deno-sandbox/blob/main/README.md Demonstrates a workaround for Python's inability to write files in the sandbox, using Deno's `fs.writeFileSync` via the `js` module. ```python import js js.fs.writeFileSync(PATH, CONTENT) ``` -------------------------------- ### Run Code Checks - Bash Source: https://github.com/bewt85/mcp-deno-sandbox/blob/main/README.md Command to check code formatting and types within the project using npm. ```bash npm run checks ``` -------------------------------- ### Fix Code Issues Automatically - Bash Source: https://github.com/bewt85/mcp-deno-sandbox/blob/main/README.md Command to automatically fix code formatting and type issues using npm. ```bash npm run fix ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.