Skip to content

Commit 2f17981

Browse files
committed
fixed documentation search tool
1 parent 70917e8 commit 2f17981

File tree

1 file changed

+12
-9
lines changed
  • cmd/mcp-victorialogs/resources

1 file changed

+12
-9
lines changed

cmd/mcp-victorialogs/resources/docs.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
var (
2828
searchIndex bleve.Index
2929
resources map[string]mcp.Resource
30+
contents map[string]mcp.ResourceContents
3031
)
3132

3233
func RegisterDocsResources(s *server.MCPServer, _ *config.Config) {
@@ -41,6 +42,7 @@ func RegisterDocsResources(s *server.MCPServer, _ *config.Config) {
4142
log.Fatal(fmt.Errorf("error listing docs files: %w", err))
4243
}
4344
resources = make(map[string]mcp.Resource, len(docFiles))
45+
contents = make(map[string]mcp.ResourceContents, len(docFiles))
4446
for _, docFile := range docFiles {
4547
resourceURI := fmt.Sprintf("%s%s#%d", docsURIPrefix, docFile.Path, docFile.ChunkNum)
4648
resource := mcp.NewResource(
@@ -52,6 +54,11 @@ func RegisterDocsResources(s *server.MCPServer, _ *config.Config) {
5254
s.AddResource(resource, docResourcesHandler)
5355

5456
resources[resourceURI] = resource
57+
contents[resourceURI] = mcp.TextResourceContents{
58+
URI: resourceURI,
59+
MIMEType: "text/markdown",
60+
Text: docFile.Content,
61+
}
5562
if err = searchIndex.Index(resourceURI, docFile); err != nil {
5663
log.Fatal(fmt.Errorf("error indexing file %s: %w", docFile.Path, err))
5764
}
@@ -90,16 +97,12 @@ func docResourcesHandler(_ context.Context, rrr mcp.ReadResourceRequest) ([]mcp.
9097
}
9198

9299
func GetDocResourceContent(uri string) (mcp.ResourceContents, error) {
93-
path := strings.TrimPrefix(uri, docsURIPrefix)
94-
content, err := GetDocFileContent(path)
95-
if err != nil {
96-
return nil, fmt.Errorf("error reading file %s: %w", path, err)
100+
content, ok := contents[uri]
101+
if !ok {
102+
return nil, fmt.Errorf("resource not found: %s", uri)
103+
97104
}
98-
return mcp.TextResourceContents{
99-
URI: uri,
100-
MIMEType: "text/markdown",
101-
Text: content,
102-
}, nil
105+
return content, nil
103106
}
104107

105108
func GetDocFileContent(path string) (string, error) {

0 commit comments

Comments
 (0)