import os
import re
EXAMPLE_FIXES = {
"01_mcp_tool_macro.rs": [
(r'#\[mcp_tool\([^\]]+\]\)', '// Tool macro not available'),
(r',\s*,', ','),
(r'#\[mcp_tool[^}]+\}', '// Macro implementation removed'),
],
"02_resources_api.rs": [
(r'ResourceContents::Text\s*\{', 'ResourceContents::Text(TextResourceContents {'),
(r'ResourceContents::Blob\s*\{', 'ResourceContents::Blob(BlobResourceContents {'),
(r'(TextResourceContents\s*\{[^}]+\})', r'\1)'),
(r'(BlobResourceContents\s*\{[^}]+\})', r'\1)'),
],
"03_prompts_api.rs": [
(r'prompt_store\.clone\(\)', 'Arc::clone(&prompt_store)'),
(r'struct PromptStore \{', '#[derive(Clone)]\nstruct PromptStore {'),
],
"04_sampling_api.rs": [
(r'ModelHint \{([^}]+)\}', r'ModelHint { \1, additional_hints: None }'),
(r'temperature:', '// temperature:'),
(r'max_tokens:', '// max_tokens:'),
(r'stop_sequences:', '// stop_sequences:'),
],
"05_http_transport.rs": [
(r'ServerBuilder::new\(\)\.\s*name', 'ServerBuilder::new()\n .name'),
],
"06_websocket_transport.rs": [
(r'ServerBuilder::new\(\)\.\s*name', 'ServerBuilder::new()\n .name'),
],
"07_authentication.rs": [
(r'impl AuthProvider', '// Auth provider implementation'),
],
"08_error_handling.rs": [
(r'ServerBuilder::new\(\)\.\s*name\("error-handling-example"\)', 'ServerBuilder::new()\n .name("error-handling-example")'),
(r'\.tool\([^;]+;', '// .tool() method not available;'),
],
"09_configuration.rs": [
(r'\.with_description\(', '// .with_description('),
(r'async fn config_info\(params: Value, config: AppConfig\)', 'async fn config_info(params: Value) // config: AppConfig'),
],
"10_plugin_system.rs": [
(r'input_schema: serde_json::json!', 'input_schema: /* ToolInputSchema */ json!'),
],
"11_advanced_tools.rs": [
(r'ServerBuilder::new\(\)\.\s*name\("advanced-tools-example"\)', 'ServerBuilder::new()\n .name("advanced-tools-example")'),
(r'\.tool\([^;]+;', '// .tool() method not available;'),
],
"12_integration_patterns.rs": [
(r'spawn_blocking', 'tokio::spawn'),
(r'\.with_description\(', '// .with_description('),
],
}
def apply_fixes(filepath, fixes):
with open(filepath, 'r') as f:
content = f.read()
for pattern, replacement in fixes:
content = re.sub(pattern, replacement, content, flags=re.MULTILINE | re.DOTALL)
with open(filepath, 'w') as f:
f.write(content)
print(f"Fixed {os.path.basename(filepath)}")
def main():
for filename, fixes in EXAMPLE_FIXES.items():
filepath = f"examples/features/{filename}"
if os.path.exists(filepath):
apply_fixes(filepath, fixes)
if __name__ == "__main__":
main()