Skip to content

Commit a976a84

Browse files
authored
feat: implement MVP for MCP Resources and Prompts
Add two new MCP specification primitives to RagCode: Resources: - ragcode://status/indexing — returns current indexing progress as JSON - Uses existing DetectContext workspace detection (X-Workspace-Root header) - Thread-safe reads from on-disk index_status.json Prompts: - "System Diagnostics" — generates a pre-filled diagnostic analysis request - Auto-detects workspace path, instructs the LLM to inspect indexing status Wiring: - resources.Register() and prompts.Register() called during daemon init in run.go - .gitignore updated for .agent/ and .trello.json Review fixes applied: - Fixed unused parameter (request → _) in prompts handler - Fixed undefined tools.BuildIndexingProgress → eng.GetIndexStatus - Removed unused tools import - Translated all inline comments to English
2 parents 90419b7 + a48a912 commit a976a84

4 files changed

Lines changed: 99 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ temp/
6464
# Scripts
6565
scripts/
6666
.ragcode/
67-
.agent/skills/
67+
.agent/
68+
.trello.json
6869
build-binaries.sh
6970

7071
# Debug logs

internal/daemon/run.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"github.com/doITmagic/rag-code-mcp/internal/healthcheck"
1818
"github.com/doITmagic/rag-code-mcp/internal/logger"
1919
"github.com/doITmagic/rag-code-mcp/internal/service/engine"
20+
"github.com/doITmagic/rag-code-mcp/internal/service/prompts"
21+
"github.com/doITmagic/rag-code-mcp/internal/service/resources"
2022
"github.com/doITmagic/rag-code-mcp/internal/service/search"
2123
"github.com/doITmagic/rag-code-mcp/internal/service/tools"
2224
"github.com/doITmagic/rag-code-mcp/internal/transport"
@@ -173,6 +175,10 @@ func Run(rcfg RunConfig) error {
173175
logger.Instance.Info("Update tools registered (auto_update=false)")
174176
}
175177

178+
// Register MCP Resources & Prompts (MVP)
179+
resources.Register(mcpServer, eng)
180+
prompts.Register(mcpServer, eng)
181+
176182
logger.Instance.Info("MCP RagCode Daemon initialized (version=%s)", rcfg.Version)
177183

178184
if cfg.AutoUpdate {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package prompts
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/doITmagic/rag-code-mcp/internal/service/engine"
8+
"github.com/modelcontextprotocol/go-sdk/mcp"
9+
)
10+
11+
// Register registers all MCP prompts provided by this package on the given mcp.Server.
12+
func Register(mcpServer *mcp.Server, eng *engine.Engine) {
13+
mcpServer.AddPrompt(&mcp.Prompt{
14+
Name: "System Diagnostics",
15+
Description: "Analyze the current indexing status and troubleshoot common issues based on the workspace resources.",
16+
Title: "Analyze RagCode Indexing System",
17+
}, func(ctx context.Context, _ *mcp.GetPromptRequest) (*mcp.GetPromptResult, error) {
18+
// Same detection as Resources: auto-detect workspace via ctx, no custom logic.
19+
wctx, err := eng.DetectContext(ctx, "")
20+
if err != nil {
21+
return nil, fmt.Errorf("failed to detect workspace: %w", err)
22+
}
23+
24+
promptText := fmt.Sprintf(`Please analyze the current indexing status of the RagCode MCP server for the workspace located at: %s
25+
26+
You can inspect the indexing status by reading the resource directly via URI: "ragcode://status/indexing" or using your available tools.
27+
Then, inform me if there are any issues such as stuck processes or parsing errors.`, wctx.Root)
28+
29+
return &mcp.GetPromptResult{
30+
Description: "Prompt to diagnose indexing and execution issues automatically.",
31+
Messages: []*mcp.PromptMessage{
32+
{
33+
Role: mcp.Role("user"),
34+
Content: &mcp.TextContent{
35+
Text: promptText,
36+
},
37+
},
38+
},
39+
}, nil
40+
})
41+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package resources
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
8+
"github.com/doITmagic/rag-code-mcp/internal/service/engine"
9+
"github.com/modelcontextprotocol/go-sdk/mcp"
10+
)
11+
12+
// Register registers all MCP resources provided by this package on the given mcp.Server.
13+
func Register(mcpServer *mcp.Server, eng *engine.Engine) {
14+
mcpServer.AddResource(&mcp.Resource{
15+
URI: "ragcode://status/indexing",
16+
Name: "Indexing Status",
17+
Description: "Returns the current indexing status and progress for the workspace.",
18+
MIMEType: "application/json",
19+
}, func(ctx context.Context, request *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error) {
20+
// Same detection mechanism used by all existing tools.
21+
// Middleware in run.go reads X-Workspace-Root from the HTTP header into ctx,
22+
// and DetectContext picks it up automatically via Tier 2 (transport.GetWorkspaceHint).
23+
wctx, err := eng.DetectContext(ctx, "")
24+
if err != nil {
25+
return nil, fmt.Errorf("failed to detect workspace: %w", err)
26+
}
27+
28+
// GetIndexStatus reads from the on-disk index_status.json,
29+
// thread-safe against the indexer writing concurrently.
30+
status := eng.GetIndexStatus(wctx.Root)
31+
if status == nil {
32+
return nil, fmt.Errorf("index status not found for workspace %s", wctx.Root)
33+
}
34+
35+
blob, err := json.MarshalIndent(status, "", " ")
36+
if err != nil {
37+
return nil, fmt.Errorf("failed to marshal index status: %w", err)
38+
}
39+
40+
return &mcp.ReadResourceResult{
41+
Contents: []*mcp.ResourceContents{
42+
{
43+
URI: request.Params.URI,
44+
MIMEType: "application/json",
45+
Text: string(blob),
46+
},
47+
},
48+
}, nil
49+
})
50+
}

0 commit comments

Comments
 (0)