-
Notifications
You must be signed in to change notification settings - Fork 1
Return map from rule ID to MCPServerConfig in Result.MCPServers() #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f77bbb9
e388f80
4e76fdf
0572a0c
3449617
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -355,6 +355,32 @@ func TestContext_Run_Basic(t *testing.T) { | |
| } | ||
| }, | ||
| }, | ||
| { | ||
| name: "task ID automatically set from filename", | ||
| setup: func(t *testing.T, dir string) { | ||
| createTask(t, dir, "my-task", "", "Task content") | ||
| }, | ||
| taskName: "my-task", | ||
| wantErr: false, | ||
| check: func(t *testing.T, result *Result) { | ||
| if result.Task.FrontMatter.ID != "my-task" { | ||
| t.Errorf("expected task ID 'my-task', got %q", result.Task.FrontMatter.ID) | ||
| } | ||
| }, | ||
| }, | ||
| { | ||
| name: "task with explicit ID in frontmatter", | ||
| setup: func(t *testing.T, dir string) { | ||
| createTask(t, dir, "file-name", "id: explicit-task-id", "Task content") | ||
| }, | ||
| taskName: "file-name", | ||
| wantErr: false, | ||
| check: func(t *testing.T, result *Result) { | ||
| if result.Task.FrontMatter.ID != "explicit-task-id" { | ||
| t.Errorf("expected task ID 'explicit-task-id', got %q", result.Task.FrontMatter.ID) | ||
| } | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
|
|
@@ -699,6 +725,46 @@ func TestContext_Run_Rules(t *testing.T) { | |
| } | ||
| }, | ||
| }, | ||
| { | ||
| name: "rule IDs automatically set from filename", | ||
| setup: func(t *testing.T, dir string) { | ||
| createTask(t, dir, "id-task", "", "Task") | ||
| createRule(t, dir, ".agents/rules/my-rule.md", "", "Rule without ID in frontmatter") | ||
| createRule(t, dir, ".agents/rules/another-rule.md", "id: explicit-id", "Rule with explicit ID") | ||
| }, | ||
| taskName: "id-task", | ||
| wantErr: false, | ||
| check: func(t *testing.T, result *Result) { | ||
| if len(result.Rules) != 2 { | ||
| t.Fatalf("expected 2 rules, got %d", len(result.Rules)) | ||
| } | ||
|
|
||
| // Check that one rule has auto-generated ID from filename | ||
| foundMyRule := false | ||
| foundAnotherRule := false | ||
| for _, rule := range result.Rules { | ||
| if rule.FrontMatter.ID == "my-rule" { | ||
| foundMyRule = true | ||
| if !strings.Contains(rule.Content, "Rule without ID") { | ||
| t.Error("my-rule should contain 'Rule without ID'") | ||
| } | ||
| } | ||
| if rule.FrontMatter.ID == "explicit-id" { | ||
| foundAnotherRule = true | ||
| if !strings.Contains(rule.Content, "Rule with explicit ID") { | ||
| t.Error("explicit-id should contain 'Rule with explicit ID'") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if !foundMyRule { | ||
| t.Error("expected to find rule with auto-generated ID 'my-rule'") | ||
| } | ||
| if !foundAnotherRule { | ||
| t.Error("expected to find rule with explicit ID 'explicit-id'") | ||
| } | ||
| }, | ||
| }, | ||
|
Comment on lines
+728
to
+767
|
||
| } | ||
|
|
||
| for _, tt := range tests { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,19 +16,21 @@ type Result struct { | |||||
| Prompt string // Combined prompt: all rules and task content | ||||||
| } | ||||||
|
|
||||||
| // MCPServers returns all MCP server configurations from rules. | ||||||
| // MCPServers returns all MCP server configurations from rules as a map. | ||||||
| // Each rule can specify one MCP server configuration. | ||||||
| // Returns a slice of all configured MCP servers from rules only. | ||||||
| // Returns a map from rule ID to MCP server configuration. | ||||||
| // Empty/zero-value MCP server configurations are filtered out. | ||||||
| func (r *Result) MCPServers() []mcp.MCPServerConfig { | ||||||
| var servers []mcp.MCPServerConfig | ||||||
| // The rule ID is automatically set to the filename (without extension) if not | ||||||
| // explicitly provided in the frontmatter. | ||||||
| func (r *Result) MCPServers() map[string]mcp.MCPServerConfig { | ||||||
| servers := make(map[string]mcp.MCPServerConfig) | ||||||
|
|
||||||
| // Add server from each rule, filtering out empty configs | ||||||
| for _, rule := range r.Rules { | ||||||
| server := rule.FrontMatter.MCPServer | ||||||
| // Skip empty MCP server configs (no command and no URL means empty) | ||||||
| if server.Command != "" || server.URL != "" { | ||||||
|
||||||
| if server.Command != "" || server.URL != "" { | |
| if (server.Command != "" || server.URL != "") && rule.FrontMatter.ID != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generateIDFromPath function does not handle edge cases such as files without extensions or multiple extensions. For example, "file.tar.gz" would result in ID "file.tar" instead of "file". Consider using filepath.Base followed by removing all extensions, or documenting this behavior if it's intentional. Also consider handling empty filenames or paths with only an extension (e.g., ".gitignore").