aia 0.9.11 → 0.9.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/CHANGELOG.md +66 -2
  4. data/README.md +133 -4
  5. data/docs/advanced-prompting.md +721 -0
  6. data/docs/cli-reference.md +582 -0
  7. data/docs/configuration.md +347 -0
  8. data/docs/contributing.md +332 -0
  9. data/docs/directives-reference.md +490 -0
  10. data/docs/examples/index.md +277 -0
  11. data/docs/examples/mcp/index.md +479 -0
  12. data/docs/examples/prompts/analysis/index.md +78 -0
  13. data/docs/examples/prompts/automation/index.md +108 -0
  14. data/docs/examples/prompts/development/index.md +125 -0
  15. data/docs/examples/prompts/index.md +333 -0
  16. data/docs/examples/prompts/learning/index.md +127 -0
  17. data/docs/examples/prompts/writing/index.md +62 -0
  18. data/docs/examples/tools/index.md +292 -0
  19. data/docs/faq.md +414 -0
  20. data/docs/guides/available-models.md +366 -0
  21. data/docs/guides/basic-usage.md +477 -0
  22. data/docs/guides/chat.md +474 -0
  23. data/docs/guides/executable-prompts.md +417 -0
  24. data/docs/guides/first-prompt.md +454 -0
  25. data/docs/guides/getting-started.md +455 -0
  26. data/docs/guides/image-generation.md +507 -0
  27. data/docs/guides/index.md +46 -0
  28. data/docs/guides/models.md +507 -0
  29. data/docs/guides/tools.md +856 -0
  30. data/docs/index.md +173 -0
  31. data/docs/installation.md +238 -0
  32. data/docs/mcp-integration.md +612 -0
  33. data/docs/prompt_management.md +579 -0
  34. data/docs/security.md +629 -0
  35. data/docs/tools-and-mcp-examples.md +1186 -0
  36. data/docs/workflows-and-pipelines.md +563 -0
  37. data/examples/tools/mcp/github_mcp_server.json +11 -0
  38. data/examples/tools/mcp/imcp.json +7 -0
  39. data/lib/aia/chat_processor_service.rb +19 -3
  40. data/lib/aia/config/base.rb +224 -0
  41. data/lib/aia/config/cli_parser.rb +409 -0
  42. data/lib/aia/config/defaults.rb +88 -0
  43. data/lib/aia/config/file_loader.rb +131 -0
  44. data/lib/aia/config/validator.rb +184 -0
  45. data/lib/aia/config.rb +10 -860
  46. data/lib/aia/directive_processor.rb +27 -372
  47. data/lib/aia/directives/configuration.rb +114 -0
  48. data/lib/aia/directives/execution.rb +37 -0
  49. data/lib/aia/directives/models.rb +178 -0
  50. data/lib/aia/directives/registry.rb +120 -0
  51. data/lib/aia/directives/utility.rb +70 -0
  52. data/lib/aia/directives/web_and_file.rb +71 -0
  53. data/lib/aia/prompt_handler.rb +23 -3
  54. data/lib/aia/ruby_llm_adapter.rb +307 -128
  55. data/lib/aia/session.rb +27 -14
  56. data/lib/aia/utility.rb +12 -8
  57. data/lib/aia.rb +11 -2
  58. data/lib/extensions/ruby_llm/.irbrc +56 -0
  59. data/mkdocs.yml +165 -0
  60. metadata +77 -20
  61. /data/{images → docs/assets/images}/aia.png +0 -0
@@ -0,0 +1,612 @@
1
+ # MCP Integration
2
+
3
+ AIA supports Model Context Protocol (MCP) clients, enabling AI models to interact with external services, databases, and applications through standardized interfaces.
4
+
5
+ ## Understanding MCP
6
+
7
+ ### What is MCP?
8
+ Model Context Protocol (MCP) is a standardized way for AI models to interact with external resources:
9
+ - **Database Access**: Query and manipulate databases
10
+ - **File System Operations**: Safe, sandboxed file operations
11
+ - **API Integrations**: Structured access to web APIs
12
+ - **Tool Extensions**: Custom functionality through protocol
13
+ - **Service Integration**: Connect to external services and platforms
14
+
15
+ ### MCP vs RubyLLM Tools
16
+ | Feature | RubyLLM Tools | MCP Clients |
17
+ |---------|---------------|-------------|
18
+ | **Language** | Ruby only | Any language |
19
+ | **Security** | Ruby sandbox | Protocol-level security |
20
+ | **Distribution** | Ruby gems/files | Separate processes |
21
+ | **Standardization** | AIA-specific | Industry standard |
22
+ | **Performance** | Direct calls | IPC overhead |
23
+
24
+ ## Enabling MCP Support
25
+
26
+ ### Configuration
27
+ ```yaml
28
+ # ~/.aia/config.yml
29
+ mcp:
30
+ enabled: true
31
+ clients:
32
+ - name: github
33
+ command: ["node", "/path/to/github-mcp-server"]
34
+ env:
35
+ GITHUB_TOKEN: "${GITHUB_TOKEN}"
36
+
37
+ - name: filesystem
38
+ command: ["mcp-server-filesystem"]
39
+ args: ["/allowed/path1", "/allowed/path2"]
40
+
41
+ - name: database
42
+ command: ["python", "/path/to/db-mcp-server.py"]
43
+ env:
44
+ DATABASE_URL: "${DATABASE_URL}"
45
+ ```
46
+
47
+ ### Command Line Usage
48
+ ```bash
49
+ # Use specific MCP clients
50
+ aia --mcp github,filesystem my_prompt
51
+
52
+ # List available MCP clients
53
+ aia --list-mcp-clients
54
+
55
+ # Debug MCP communication
56
+ aia --debug --mcp github github_analysis
57
+ ```
58
+
59
+ ## Available MCP Clients
60
+
61
+ ### GitHub Integration
62
+ Connect to GitHub repositories and operations:
63
+
64
+ ```bash
65
+ # Install GitHub MCP server
66
+ npm install -g @anthropic-ai/mcp-server-github
67
+
68
+ # Configure in ~/.aia/config.yml
69
+ mcp:
70
+ clients:
71
+ - name: github
72
+ command: ["npx", "@anthropic-ai/mcp-server-github"]
73
+ env:
74
+ GITHUB_TOKEN: "${GITHUB_TOKEN}"
75
+ ```
76
+
77
+ **Capabilities**:
78
+ - Repository analysis
79
+ - Issue management
80
+ - Pull request operations
81
+ - File content access
82
+ - Commit history analysis
83
+
84
+ ### File System Access
85
+ Safe file system operations with sandboxing:
86
+
87
+ ```bash
88
+ # Install filesystem MCP server
89
+ npm install -g @anthropic-ai/mcp-server-filesystem
90
+
91
+ # Configure with allowed paths
92
+ mcp:
93
+ clients:
94
+ - name: filesystem
95
+ command: ["npx", "@anthropic-ai/mcp-server-filesystem"]
96
+ args: ["/home/user/projects", "/tmp/aia-workspace"]
97
+ ```
98
+
99
+ **Capabilities**:
100
+ - Read files and directories
101
+ - Write files (in allowed paths)
102
+ - File metadata access
103
+ - Directory traversal
104
+ - Search operations
105
+
106
+ ### Database Integration
107
+ Connect to SQL databases:
108
+
109
+ ```python
110
+ # Example database MCP server (Python)
111
+ #!/usr/bin/env python3
112
+ import asyncio
113
+ import os
114
+ from mcp.server import Server
115
+ from mcp.types import Resource, Tool
116
+ import sqlite3
117
+
118
+ server = Server("database-mcp")
119
+
120
+ @server.list_tools()
121
+ async def list_tools():
122
+ return [
123
+ Tool(name="query", description="Execute SQL query"),
124
+ Tool(name="describe", description="Describe table structure")
125
+ ]
126
+
127
+ @server.call_tool()
128
+ async def call_tool(name: str, arguments: dict):
129
+ if name == "query":
130
+ return execute_query(arguments["sql"])
131
+ elif name == "describe":
132
+ return describe_table(arguments["table"])
133
+ ```
134
+
135
+ ## Using MCP Clients in Prompts
136
+
137
+ ### GitHub Analysis
138
+ ```markdown
139
+ # ~/.prompts/github_analysis.txt
140
+ //mcp github
141
+
142
+ # GitHub Repository Analysis
143
+
144
+ Repository: <%= repo_url %>
145
+
146
+ ## Repository Overview
147
+ Use the GitHub MCP client to analyze:
148
+ 1. Repository structure and organization
149
+ 2. Recent commit activity and patterns
150
+ 3. Open issues and their categories
151
+ 4. Pull request status and reviews
152
+ 5. Contributors and contribution patterns
153
+
154
+ ## Code Quality Assessment
155
+ Examine key files:
156
+ - README and documentation quality
157
+ - Code organization and structure
158
+ - Testing coverage and practices
159
+ - Dependency management
160
+
161
+ Provide comprehensive analysis with actionable recommendations.
162
+ ```
163
+
164
+ ### File System Operations
165
+ ```markdown
166
+ # ~/.prompts/project_analysis.txt
167
+ //mcp filesystem
168
+
169
+ # Project Structure Analysis
170
+
171
+ Project directory: <%= project_path %>
172
+
173
+ ## Structure Analysis
174
+ Use the filesystem MCP client to:
175
+ 1. Map directory structure and organization
176
+ 2. Identify configuration files and their purposes
177
+ 3. Analyze code distribution across languages
178
+ 4. Find documentation and README files
179
+ 5. Locate test files and coverage
180
+
181
+ ## Code Organization Review
182
+ Examine:
183
+ - Logical grouping of related files
184
+ - Naming conventions consistency
185
+ - Dependency organization
186
+ - Build and deployment configurations
187
+
188
+ Generate detailed project assessment with improvement suggestions.
189
+ ```
190
+
191
+ ### Database Schema Analysis
192
+ ```markdown
193
+ # ~/.prompts/database_analysis.txt
194
+ //mcp database
195
+
196
+ # Database Schema Analysis
197
+
198
+ Database: <%= database_name %>
199
+
200
+ ## Schema Overview
201
+ Use the database MCP client to:
202
+ 1. List all tables and their relationships
203
+ 2. Analyze table structures and data types
204
+ 3. Identify primary keys and foreign key relationships
205
+ 4. Examine indexes and constraints
206
+ 5. Review stored procedures and views
207
+
208
+ ## Data Quality Assessment
209
+ Check for:
210
+ - Naming convention consistency
211
+ - Normalization level appropriateness
212
+ - Index optimization opportunities
213
+ - Data integrity constraints
214
+ - Performance bottlenecks
215
+
216
+ Provide recommendations for schema improvements and optimizations.
217
+ ```
218
+
219
+ ## Advanced MCP Integration
220
+
221
+ ### Multi-Client Workflows
222
+ ```markdown
223
+ # ~/.prompts/full_project_audit.txt
224
+ //mcp github,filesystem,database
225
+
226
+ # Comprehensive Project Audit
227
+
228
+ Project: <%= project_name %>
229
+ Repository: <%= repo_url %>
230
+ Database: <%= db_name %>
231
+
232
+ ## Phase 1: Code Repository Analysis
233
+ Using GitHub MCP client:
234
+ - Repository health and activity
235
+ - Code quality and organization
236
+ - Issue and PR management
237
+ - Developer productivity metrics
238
+
239
+ ## Phase 2: File System Structure
240
+ Using filesystem MCP client:
241
+ - Local project organization
242
+ - Configuration management
243
+ - Documentation completeness
244
+ - Build and deployment setup
245
+
246
+ ## Phase 3: Database Architecture
247
+ Using database MCP client:
248
+ - Schema design and integrity
249
+ - Performance optimization
250
+ - Data governance compliance
251
+ - Migration and versioning
252
+
253
+ ## Integration Assessment
254
+ Cross-analyze findings to identify:
255
+ - Consistency across repository and local files
256
+ - Database schema alignment with application code
257
+ - Documentation accuracy and completeness
258
+ - Deployment and configuration coherence
259
+
260
+ Generate comprehensive audit report with prioritized recommendations.
261
+ ```
262
+
263
+ ### Conditional MCP Usage
264
+ ```ruby
265
+ # ~/.prompts/adaptive_mcp.txt
266
+ //ruby
267
+ project_type = '<%= project_type %>'
268
+ has_database = '<%= has_database %>' == 'true'
269
+ is_open_source = '<%= is_open_source %>' == 'true'
270
+
271
+ mcp_clients = []
272
+ mcp_clients << 'filesystem' # Always analyze file structure
273
+ mcp_clients << 'github' if is_open_source
274
+ mcp_clients << 'database' if has_database
275
+
276
+ puts "//mcp #{mcp_clients.join(',')}"
277
+ puts "Selected MCP clients for #{project_type} project: #{mcp_clients.join(', ')}"
278
+ ```
279
+
280
+ # Adaptive Project Analysis
281
+
282
+ Project type: <%= project_type %>
283
+ Analysis scope: <%= mcp_clients.join(', ') %>
284
+
285
+ Perform comprehensive analysis using available MCP clients to provide insights specific to this project type.
286
+ ```
287
+
288
+ ## Custom MCP Client Development
289
+
290
+ ### Basic MCP Server Structure
291
+ ```python
292
+ # custom_mcp_server.py
293
+ import asyncio
294
+ from mcp.server import Server
295
+ from mcp.types import Resource, Tool, TextContent
296
+
297
+ server = Server("custom-service")
298
+
299
+ @server.list_resources()
300
+ async def list_resources():
301
+ return [
302
+ Resource(
303
+ uri="service://data/users",
304
+ name="User Data",
305
+ description="Access to user information"
306
+ )
307
+ ]
308
+
309
+ @server.list_tools()
310
+ async def list_tools():
311
+ return [
312
+ Tool(
313
+ name="get_user",
314
+ description="Retrieve user information by ID",
315
+ inputSchema={
316
+ "type": "object",
317
+ "properties": {
318
+ "user_id": {"type": "string"}
319
+ },
320
+ "required": ["user_id"]
321
+ }
322
+ )
323
+ ]
324
+
325
+ @server.call_tool()
326
+ async def call_tool(name: str, arguments: dict):
327
+ if name == "get_user":
328
+ user_data = fetch_user(arguments["user_id"])
329
+ return TextContent(type="text", text=str(user_data))
330
+
331
+ def fetch_user(user_id):
332
+ # Custom logic to fetch user data
333
+ return {"id": user_id, "name": "Example User"}
334
+
335
+ if __name__ == "__main__":
336
+ asyncio.run(server.run())
337
+ ```
338
+
339
+ ### Node.js MCP Server
340
+ ```javascript
341
+ // custom-mcp-server.js
342
+ const { Server } = require('@anthropic-ai/mcp-sdk/server');
343
+
344
+ const server = new Server('custom-service', '1.0.0');
345
+
346
+ server.setRequestHandler('tools/list', async () => {
347
+ return {
348
+ tools: [
349
+ {
350
+ name: 'process_data',
351
+ description: 'Process custom data',
352
+ inputSchema: {
353
+ type: 'object',
354
+ properties: {
355
+ data: { type: 'string' },
356
+ format: { type: 'string', enum: ['json', 'csv', 'xml'] }
357
+ },
358
+ required: ['data']
359
+ }
360
+ }
361
+ ]
362
+ };
363
+ });
364
+
365
+ server.setRequestHandler('tools/call', async (request) => {
366
+ const { name, arguments: args } = request.params;
367
+
368
+ if (name === 'process_data') {
369
+ const result = processData(args.data, args.format || 'json');
370
+ return { content: [{ type: 'text', text: result }] };
371
+ }
372
+
373
+ throw new Error(`Unknown tool: ${name}`);
374
+ });
375
+
376
+ function processData(data, format) {
377
+ // Custom processing logic
378
+ return `Processed data in ${format} format: ${data}`;
379
+ }
380
+
381
+ server.connect();
382
+ ```
383
+
384
+ ## MCP Security and Best Practices
385
+
386
+ ### Security Configuration
387
+ ```yaml
388
+ # Secure MCP configuration
389
+ mcp:
390
+ security:
391
+ sandbox_mode: true
392
+ allowed_operations: ["read", "list"]
393
+ blocked_operations: ["delete", "execute"]
394
+
395
+ resource_limits:
396
+ max_file_size: 10485760 # 10MB
397
+ max_query_results: 1000
398
+ timeout_seconds: 30
399
+
400
+ clients:
401
+ - name: filesystem
402
+ command: ["mcp-server-filesystem"]
403
+ args: ["/safe/path/only"]
404
+ security_context: "restricted"
405
+
406
+ - name: database
407
+ command: ["database-mcp-server"]
408
+ security_context: "read_only"
409
+ env:
410
+ DB_READ_ONLY: "true"
411
+ ```
412
+
413
+ ### Access Control
414
+ ```ruby
415
+ # MCP access control in prompts
416
+ //ruby
417
+ user_role = '<%= user_role %>'
418
+ allowed_mcp = case user_role
419
+ when 'admin'
420
+ ['github', 'filesystem', 'database']
421
+ when 'developer'
422
+ ['github', 'filesystem']
423
+ when 'analyst'
424
+ ['database']
425
+ else
426
+ []
427
+ end
428
+
429
+ if allowed_mcp.empty?
430
+ puts "No MCP access for role: #{user_role}"
431
+ else
432
+ puts "//mcp #{allowed_mcp.join(',')}"
433
+ puts "MCP access granted: #{allowed_mcp.join(', ')}"
434
+ end
435
+ ```
436
+
437
+ ## Performance Optimization
438
+
439
+ ### Connection Pooling
440
+ ```yaml
441
+ mcp:
442
+ connection_pooling:
443
+ enabled: true
444
+ max_connections: 5
445
+ idle_timeout: 300
446
+
447
+ caching:
448
+ enabled: true
449
+ ttl: 3600 # 1 hour
450
+ max_size: 100 # Cache entries
451
+ ```
452
+
453
+ ### Async Operations
454
+ ```python
455
+ # Async MCP server for better performance
456
+ import asyncio
457
+ import aiohttp
458
+ from mcp.server import Server
459
+
460
+ server = Server("async-service")
461
+
462
+ @server.call_tool()
463
+ async def call_tool(name: str, arguments: dict):
464
+ if name == "fetch_data":
465
+ async with aiohttp.ClientSession() as session:
466
+ async with session.get(arguments["url"]) as response:
467
+ data = await response.text()
468
+ return TextContent(type="text", text=data)
469
+ ```
470
+
471
+ ## Troubleshooting MCP
472
+
473
+ ### Common Issues
474
+
475
+ #### Client Connection Failures
476
+ ```bash
477
+ # Debug MCP client connections
478
+ aia --debug --mcp github test_prompt
479
+
480
+ # Check client status
481
+ aia --mcp-status
482
+
483
+ # Test individual client
484
+ aia --test-mcp github
485
+ ```
486
+
487
+ #### Protocol Errors
488
+ ```yaml
489
+ # Enable detailed MCP logging
490
+ mcp:
491
+ logging:
492
+ level: debug
493
+ file: /tmp/aia-mcp.log
494
+
495
+ error_handling:
496
+ retry_attempts: 3
497
+ retry_delay: 1000 # milliseconds
498
+ fallback_mode: graceful
499
+ ```
500
+
501
+ #### Performance Issues
502
+ ```bash
503
+ # Monitor MCP performance
504
+ aia --mcp-metrics github filesystem
505
+
506
+ # Profile MCP operations
507
+ aia --profile --mcp database analysis_prompt
508
+ ```
509
+
510
+ ### Debugging Tools
511
+ ```python
512
+ # MCP debugging utilities
513
+ async def debug_mcp_call(client, tool, args):
514
+ start_time = time.time()
515
+ try:
516
+ result = await client.call_tool(tool, args)
517
+ duration = time.time() - start_time
518
+ print(f"MCP call successful: {tool} in {duration:.2f}s")
519
+ return result
520
+ except Exception as e:
521
+ duration = time.time() - start_time
522
+ print(f"MCP call failed: {tool} after {duration:.2f}s - {e}")
523
+ raise
524
+ ```
525
+
526
+ ## MCP Examples Repository
527
+
528
+ ### GitHub Repository Analysis
529
+ ```markdown
530
+ # ~/.prompts/mcp_examples/github_repo_health.txt
531
+ //mcp github
532
+
533
+ # GitHub Repository Health Check
534
+
535
+ Repository: <%= repository %>
536
+
537
+ ## Comprehensive Health Analysis
538
+ 1. **Activity Metrics**
539
+ - Commit frequency and patterns
540
+ - Contributor activity and distribution
541
+ - Issue resolution time and patterns
542
+ - Pull request merge rates
543
+
544
+ 2. **Code Quality Indicators**
545
+ - Documentation coverage
546
+ - Test file presence and organization
547
+ - Dependency management practices
548
+ - Security vulnerability reports
549
+
550
+ 3. **Community Engagement**
551
+ - Issue discussion quality
552
+ - Response times to community contributions
553
+ - Maintainer activity levels
554
+ - Project governance clarity
555
+
556
+ 4. **Technical Debt Assessment**
557
+ - Outstanding bugs and technical issues
558
+ - Code review thoroughness
559
+ - Deprecated dependency usage
560
+ - Architecture evolution patterns
561
+
562
+ Generate detailed health score with specific improvement recommendations.
563
+ ```
564
+
565
+ ### File System Audit
566
+ ```markdown
567
+ # ~/.prompts/mcp_examples/filesystem_audit.txt
568
+ //mcp filesystem
569
+
570
+ # File System Security and Organization Audit
571
+
572
+ Target directory: <%= target_path %>
573
+
574
+ ## Security Assessment
575
+ 1. **Permission Analysis**
576
+ - File and directory permissions
577
+ - Ownership consistency
578
+ - Sensitive file exposure
579
+ - Configuration file security
580
+
581
+ 2. **Organization Review**
582
+ - Directory structure logic
583
+ - File naming consistency
584
+ - Duplicate file detection
585
+ - Orphaned file identification
586
+
587
+ 3. **Compliance Check**
588
+ - Standard directory compliance
589
+ - Required file presence
590
+ - Documentation completeness
591
+ - License file availability
592
+
593
+ 4. **Optimization Opportunities**
594
+ - Large file identification
595
+ - Unused file detection
596
+ - Archive opportunities
597
+ - Cleanup recommendations
598
+
599
+ Provide prioritized action plan for security and organization improvements.
600
+ ```
601
+
602
+ ## Related Documentation
603
+
604
+ - [Tools Integration](guides/tools.md) - RubyLLM tools vs MCP comparison
605
+ - [Advanced Prompting](advanced-prompting.md) - Complex MCP integration patterns
606
+ - [Configuration](configuration.md) - MCP configuration options
607
+ - [Security Best Practices](security.md) - MCP security guidelines
608
+ - [Examples](examples/mcp/index.md) - Real-world MCP examples
609
+
610
+ ---
611
+
612
+ MCP integration extends AIA's capabilities beyond Ruby tools, providing standardized access to external services and enabling complex, multi-system workflows. Start with simple integrations and gradually build more sophisticated MCP-based solutions!