Commit ad8a9b4
authored
feat: MCP (Model Context Protocol) integration (#57)
* feat: MCP (Model Context Protocol) integration
Add support for external MCP tool servers as typed sandbox modules.
MCP tools appear as host:mcp-<name> modules — identical to native plugins.
MCP framework:
- Config parser with validation, env var substitution, tool filtering
- Client manager with lazy connect, timeouts, reconnect (max 3)
- Plugin adapter generating TypeScript declarations from tool schemas
- Sanitisation: tool names, descriptions, prompt injection detection
- Approval store with SHA-256 config hashing
Gateway plugin (plugins/mcp/):
- Gates the entire MCP subsystem via normal plugin audit/approve flow
- Individual servers require separate approval via /mcp enable
SDK tools for LLM discovery:
- list_mcp_servers() — configured servers, state, tool counts
- mcp_server_info(name) — detailed info + TypeScript declarations
- manage_mcp(action, name) — connect/disconnect servers
Slash commands: /mcp list|enable|disable|info|approve|revoke
Validator improvements:
- strip_js_comments() — comments stripped once, all checks use clean source
- require(), Buffer, process, __dirname, __filename are now hard errors
- Handler return check with brace-matched scope (not string search)
- Comment-safe parsing prevents false positives from quotes in comments
Other fixes:
- Double-prompt eliminated for plugins with no config schema
- Canary injection findings filtered from audit RATING section
- MCP module author type fixed (system, not mcp)
- Dynamic .d.ts uses export declare function (not bare export)
Docs: docs/MCP.md with config reference, security model, GitHub example
Scripts: just mcp-setup-everything|github|filesystem|show-config
Tests: 33 new tests (config, sanitise, audit, type gen, validator integration)
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
* fix: add /mcp commands to help, tab-completion, and history
The /mcp commands were implemented in slash-commands.ts but missing
from the COMMANDS registry in commands.ts. This caused:
- /help not showing MCP commands
- Tab-completion not offering /mcp suggestions
- /mcp commands silently dropped from readline history
Add 6 MCP command entries to COMMANDS array and 'mcp' GROUP_ALIAS
so /help mcp works.
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
* fix: address 8 PR review comments
1. approval.ts: mkdir ~/.hyperagent/ before writing (first-run case)
2. config.ts: hash includes allowTools, denyTools, env key names
3. approval.ts: isMCPApproved checks tool list matches approved tools
4. plugin-adapter.ts: quote property names that aren't valid JS identifiers
5. plugins/mcp/index.ts: fix comment to match implementation (sentinel module)
6. index.ts: module_info author fixed to 'system' (was 'mcp')
7. validator.rs: arrow handler param check distinguishes () => from (event) =>
8. validator.rs: strip_js_comments guards against regex literal // sequences
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
---------
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>1 parent 1c79da4 commit ad8a9b4
File tree
23 files changed
+7221
-2446
lines changed- docs
- design
- plugins/mcp
- src
- agent
- mcp
- code-validator/guest/runtime/src
- plugin-system
- tests
23 files changed
+7221
-2446
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
569 | 569 | | |
570 | 570 | | |
571 | 571 | | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
0 commit comments