coot-best-practices
БесплатноБез исполняемых скриптовНе проверенBest Practices for using Coot MCP
Об этом скилле
Coot Python API Best Practices
Overview
This skill provides best practices for interacting with Coot's Python API through the MCP server. Following these guidelines ensures optimal performance, correct usage, and reliable results.
Python Execution in Coot MCP
CRITICAL: Understanding run_python() vs run_python_multiline()
Coot MCP provides two tools for executing Python code with different capabilities and limitations:
run_python() - Simple Expressions Only
Use for single expressions that return a value. Cannot handle imports or semicolons.
# ✓ CORRECT - single expression, no imports
coot.run_python("1 + 1") # Returns: 2
coot.run_python("coot.molecule_name(0)") # Returns: molecule name
coot.run_python("coot.is_valid_model_molecule(0)") # Returns: 1 or 0
# ✗ WRONG - these will all fail with syntax errors
coot.run_python("import os") # FAILS - import not allowed
coot.run_python("import os; os.getcwd()") # FAILS - semicolon not allowed
coot.run_python("x = 5; x * 2") # FAILS - semicolon not allowed
coot.run_python("import coot_utils; coot_utils.chain_ids(0)") # FAILS
Rule: Use run_python() ONLY for:
- Single expressions with no semicolons
- No import statements
- Direct function calls that return a value
run_python_multiline() - Everything Else
Use for any code requiring imports, multiple statements, or function definitions:
# ✓ CORRECT - use multiline for imports
coot.run_python_multiline("""
import os
result = os.getcwd()
print(result)
""")
# ✓ CORRECT - use multiline for multiple statements
coot.run_python_multiline("""
x = 5
y = x * 2
print(y)
""")
# ✓ CORRECT - use multiline for complex logic
coot.run_python_multiline("""
import coot_utils
chains = coot_utils.chain_ids(0)
for chain in chains:
print(f"Chain: {chain}")
""")
# ✓ CORRECT - use multiline for function definitions
coot.run_python_multiline("""
def validate_residue(imol, chain, resno):
info = coot.residue_info_py(imol, chain, resno, "")
return len(info)
result = validate_residue(0, "A", 42)
print(f"Atoms: {result}")
""")
Rule: Use run_python_multiline() for:
- Any import statements
- Multiple statements (even without imports)
- Function definitions
- Loops and control flow
- Anything with complexity
Key Differences Table
| Feature | run_python() | run_python_multiline() |
|---|---|---|
| Import statements | ❌ Fails | ✓ Works |
| Semicolons | ❌ Fails | ✓ Works |
| Multiple lines | ❌ Fails | ✓ Works |
| Function defs | ❌ Fails | ✓ Works |
| Simple expressions | ✓ Works | ✓ Works |
| Return value | Returns value | Returns None (use print) |
Common Mistake Pattern
# ❌ WRONG - will fail with "invalid syntax"
result = coot.run_python("import coot_utils; coot_utils.chain_ids(0)")
# ✓ CORRECT - use multiline
coot.run_python_multiline("""
import coot_utils
chains = coot_utils.chain_ids(0)
print(chains)
""")
When in Doubt
Use run_python_multiline() - it handles everything run_python() can do, plus more. The only downside is that it returns None rather than a value, so use print() to see output.
File Writing from Coot Python
CRITICAL: When writing files from Coot's Python, ALWAYS write to the current directory without specifying a path.
The Problem
Coot's Python interpreter runs in a specific working directory (/Users/pemsley/Projects/coot/git/coot-main/build/src), which is different from both:
- The bash working directory (
/home/claude) - Mounted shared directories (
/mnt/user-data/...)
Attempting to write to an explicit path that doesn't exist in Coot's context will cause FileNotFoundError.
✅ CORRECT: Write to Current Directory
# ✓ CORRECT - no path, just filename
with open('output.txt', 'w') as f:
f.write(content)
# ✓ CORRECT - works for any file type
with open('validation.xml', 'w') as f:
f.write(xml_content)
# ✓ CORRECT - reading also uses just filename
with open('data.txt', 'r') as f:
content = f.read()
❌ INCORRECT: Don't Specify Paths
# ✗ WRONG - will fail with FileNotFoundError
with open('/home/claude/output.txt', 'w') as f:
f.write(content)
# ✗ WRONG - this path doesn't exist in Coot's context
with open('/mnt/user-data/outputs/file.txt', 'w') as f:
f.write(content)
# ✗ WRONG - even full paths will fail
import os
output_file = os.path.join('/home/claude', 'output.txt')
with open(output_file, 'w') as f:
f.write(content)
Pattern for Working with Files
# 1. Download/fetch content (if needed)
url = "https://example.com/data.xml"
content = coot.coot_get_url_as_string_py(url)
# 2. Write to current directory (no path!)
with open('data.xml', 'w') as f:
f.write(content)
# 3. Process the file
import xml.etree.ElementTree as ET
tree = ET.parse('data.xml') # Read from current directory
root
Установить coot-best-practices в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл coot-best-practices?
Best Practices for using Coot MCP
Как установить скилл coot-best-practices?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл coot-best-practices запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic