Skip to content

Commit 444045b

Browse files
committed
feat: implement MVP for MCP Resources and Prompts
- Add internal/service/resources package exposing ragcode://status/indexing - Add internal/service/prompts package exposing System Diagnostics prompt - Wire both into internal/daemon/run.go after tools registration - Both use eng.DetectContext(ctx, "") identical to existing tools - BuildIndexingProgress is thread-safe (sync.Mutex + deep-copy)
1 parent 595619a commit 444045b

4 files changed

Lines changed: 100 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ temp/
6161
# Scripts
6262
scripts/
6363
.ragcode/
64-
.agent/skills/
64+
.agent/
65+
.trello.json
6566
build-binaries.sh
6667

6768
# Debug logs

internal/daemon/run.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"github.com/doITmagic/rag-code-mcp/internal/healthcheck"
1616
"github.com/doITmagic/rag-code-mcp/internal/logger"
1717
"github.com/doITmagic/rag-code-mcp/internal/service/engine"
18+
"github.com/doITmagic/rag-code-mcp/internal/service/prompts"
19+
"github.com/doITmagic/rag-code-mcp/internal/service/resources"
1820
"github.com/doITmagic/rag-code-mcp/internal/service/search"
1921
"github.com/doITmagic/rag-code-mcp/internal/service/tools"
2022
"github.com/doITmagic/rag-code-mcp/internal/transport"
@@ -164,6 +166,10 @@ func Run(rcfg RunConfig) error {
164166
tools.NewCheckUpdateTool(rcfg.Version, cfg).Register(mcpServer)
165167
tools.NewApplyUpdateTool(rcfg.Version).Register(mcpServer)
166168

169+
// Register MCP Resources & Prompts (MVP)
170+
resources.Register(mcpServer, eng)
171+
prompts.Register(mcpServer, eng)
172+
167173
logger.Instance.Info("MCP RagCode Daemon initialized (version=%s)", rcfg.Version)
168174

169175
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, request *mcp.GetPromptRequest) (*mcp.GetPromptResult, error) {
18+
// Idem cu Resources: detectie automata prin ctx, fara logica proprie.
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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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/doITmagic/rag-code-mcp/internal/service/tools"
10+
"github.com/modelcontextprotocol/go-sdk/mcp"
11+
)
12+
13+
// Register registers all MCP resources provided by this package on the given mcp.Server.
14+
func Register(mcpServer *mcp.Server, eng *engine.Engine) {
15+
mcpServer.AddResource(&mcp.Resource{
16+
URI: "ragcode://status/indexing",
17+
Name: "Indexing Status",
18+
Description: "Returns the current indexing status and progress for the workspace.",
19+
MIMEType: "application/json",
20+
}, func(ctx context.Context, request *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error) {
21+
// Folosim exact acelasi mechanism de detectie ca toate tool-urile existente.
22+
// Middleware-ul din run.go injecteaza X-Workspace-Root din header in ctx,
23+
// iar DetectContext il preia automat din Tier 2 (transport.GetWorkspaceHint).
24+
wctx, err := eng.DetectContext(ctx, "")
25+
if err != nil {
26+
return nil, fmt.Errorf("failed to detect workspace: %w", err)
27+
}
28+
29+
// BuildIndexingProgress citeste din progressStore (sync.Mutex + deep-copy),
30+
// thread-safe fata de indexer-ul care scrie simultan.
31+
status := tools.BuildIndexingProgress(eng, wctx.ID, wctx.Root)
32+
if status == nil {
33+
return nil, fmt.Errorf("index status not found for workspace %s", wctx.Root)
34+
}
35+
36+
blob, err := json.MarshalIndent(status, "", " ")
37+
if err != nil {
38+
return nil, fmt.Errorf("failed to marshal index status: %w", err)
39+
}
40+
41+
return &mcp.ReadResourceResult{
42+
Contents: []*mcp.ResourceContents{
43+
{
44+
URI: request.Params.URI,
45+
MIMEType: "application/json",
46+
Text: string(blob),
47+
},
48+
},
49+
}, nil
50+
})
51+
}

0 commit comments

Comments
 (0)