dew/packages/mcp/test/mcp_test.dart
Chris Hendrickson 7b83572f7a Unified command-tool registration via DewToolCommand mixin
- Add DewToolCommand mixin that auto-derives MCP tool JSON Schema from
  ArgParser, eliminating the need to define CLI commands and MCP tools
  separately
- Add schemaFromArgParser() to generate JSON Schema from ArgParser options
- Add CommandRegistry.mcpTools recursive collector for all DewToolCommand
  subcommands
- Refactor all kanban subcommands to use the mixin; switch get/update/delete
  from positional rest args to --id / -i option for schema compatibility
- Promote list to a proper CLI subcommand (was MCP-only before)
- Add search, comment, and config subcommands (CLI + MCP tools)
- Add TicketStore.addComment() for non-destructive comment appending
- Simplify mcp.registerCommands() to take only CommandRegistry
- Simplify CLI entry point (no more KanbanToolProvider/McpToolRegistry)
- Delete stale files: kanban_tool_provider.dart, mcp_tool_provider.dart,
  mcp_tool_registry.dart (superseded by DewToolCommand mixin)
- Add tools/mcp_client.dart debug client for manual MCP server testing
- Update .vscode/mcp.json with correct server config

All 26 tests pass, dart analyze clean.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-23 16:30:43 -04:00

67 lines
1.8 KiB
Dart

import 'package:dew_core/dew_core.dart';
import 'package:dew_mcp/dew_mcp.dart';
import 'package:test/test.dart';
void main() {
group('McpCommand', () {
test('has correct name and description', () {
final cmd = McpCommand(CommandRegistry());
expect(cmd.name, 'mcp');
expect(cmd.description, isNotEmpty);
});
test('has serve subcommand', () {
final cmd = McpCommand(CommandRegistry());
expect(cmd.subcommands.keys, contains('serve'));
});
test('registerCommands adds mcp command to registry', () {
final registry = CommandRegistry();
registerCommands(registry);
expect(registry.commands.map((c) => c.name), contains('mcp'));
});
});
group('CommandRegistry.mcpTools', () {
test('starts empty with no feature packages registered', () {
expect(CommandRegistry().mcpTools, isEmpty);
});
test('collects tools from DewToolCommand subcommands', () {
final registry = CommandRegistry();
registry.register(_StubParentCommand());
expect(registry.mcpTools, hasLength(1));
expect(registry.mcpTools.first.name, 'stub_tool');
});
});
}
class _StubToolCommand extends DewCommand with DewToolCommand {
_StubToolCommand() {
argParser.addOption('input', mandatory: true, help: 'Some input.');
}
@override
final String name = 'stub';
@override
final String description = 'A stub tool command.';
@override
final String toolName = 'stub_tool';
@override
Future<String> callAsTool(Map<String, dynamic> args) async => 'ok';
}
class _StubParentCommand extends DewCommand {
_StubParentCommand() {
addSubcommand(_StubToolCommand());
}
@override
final String name = 'parent';
@override
final String description = 'Parent.';
@override
Future<void> run() async => printUsage();
}