Skip to content

Commit 6a69434

Browse files
authored
Merge pull request #1 from GollyTicker/main
feat: Add 'limit' of contexts to return in simple search
2 parents eed576c + aa3e962 commit 6a69434

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

openapi.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,13 @@ paths:
15501550
schema:
15511551
default: 100
15521552
type: "number"
1553+
- description: "How many contexts to return at most"
1554+
in: "query"
1555+
name: "limit"
1556+
required: false
1557+
schema:
1558+
default: 100
1559+
type: "number"
15531560
responses:
15541561
"200":
15551562
content:

src/mcp_obsidian/obsidian.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ def get_batch_file_contents(self, filepaths: list[str]) -> str:
186186

187187
return "".join(result)
188188

189-
def search(self, query: str, context_length: int = 100) -> Any:
189+
def search(self, query: str, context_length: int = 100, limit: int = 100) -> Any:
190190
url = f"{self.get_base_url()}/search/simple/"
191-
params = {"query": query, "contextLength": context_length}
191+
params = {"query": query, "contextLength": context_length, "limit": limit}
192192

193193
def call_fn():
194194
response = requests.post(

src/mcp_obsidian/tools.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ def get_tool_description(self):
166166
"context_length": {
167167
"type": "integer",
168168
"description": "How much context to return around the matching string (default: 100)",
169-
"default": 100,
169+
"default": 100
170+
},
171+
"limit": {
172+
"type": "integer",
173+
"description": "How many contexts to return at most (default: 100)",
174+
"default": 100
170175
},
171176
},
172177
"required": ["query"],
@@ -180,14 +185,20 @@ def run_tool(
180185
raise RuntimeError("query argument missing in arguments")
181186

182187
context_length = args.get("context_length", 100)
183-
188+
limit = args.get("limit", 100)
189+
184190
api = obsidian.Obsidian(api_key=api_key, host=obsidian_host)
185-
results = api.search(args["query"], context_length)
186-
191+
results = api.search(args["query"], context_length, limit)
192+
187193
formatted_results = []
194+
total_results = 0
188195
for result in results:
196+
if total_results >= limit:
197+
break
189198
formatted_matches = []
190199
for match in result.get("matches", []):
200+
if total_results >= limit:
201+
break
191202
context = match.get("context", "")
192203
match_pos = match.get("match", {})
193204
start = match_pos.get("start", 0)
@@ -196,6 +207,7 @@ def run_tool(
196207
formatted_matches.append(
197208
{"context": context, "match_position": {"start": start, "end": end}}
198209
)
210+
total_results = total_results + 1
199211

200212
formatted_results.append(
201213
{

0 commit comments

Comments
 (0)