Add code-search-mcp module: JavaParser index, swappable embedder and three MCP tools on the 2026-07-28 stateless spec (MCP Java SDK 2.2.0)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6BHcz4muRH44T3br3
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
26e0a3875a
commit
e116c4d5a4
@@ -0,0 +1,37 @@
|
||||
# Indexing sample-monorepo with JavaParser
|
||||
files parsed: 10
|
||||
parse problems: 0
|
||||
types: 10
|
||||
methods+constructors:20
|
||||
|
||||
## every unit: kind, short name, file:line
|
||||
TYPE InventoryRepository inventory/src/main/java/shop/inventory/InventoryRepository.java:7
|
||||
METHOD InventoryRepository#save inventory/src/main/java/shop/inventory/InventoryRepository.java:12
|
||||
METHOD InventoryRepository#get inventory/src/main/java/shop/inventory/InventoryRepository.java:18
|
||||
TYPE InventoryService inventory/src/main/java/shop/inventory/InventoryService.java:4
|
||||
METHOD InventoryService#InventoryService inventory/src/main/java/shop/inventory/InventoryService.java:8
|
||||
METHOD InventoryService#reserve inventory/src/main/java/shop/inventory/InventoryService.java:13
|
||||
METHOD InventoryService#release inventory/src/main/java/shop/inventory/InventoryService.java:22
|
||||
TYPE StockItem inventory/src/main/java/shop/inventory/StockItem.java:4
|
||||
TYPE AuditTrail notifications/src/main/java/shop/notifications/AuditTrail.java:6
|
||||
METHOD AuditTrail#AuditTrail notifications/src/main/java/shop/notifications/AuditTrail.java:10
|
||||
METHOD AuditTrail#recordEmail notifications/src/main/java/shop/notifications/AuditTrail.java:15
|
||||
TYPE EmailNotifier notifications/src/main/java/shop/notifications/EmailNotifier.java:4
|
||||
METHOD EmailNotifier#sendConfirmation notifications/src/main/java/shop/notifications/EmailNotifier.java:7
|
||||
METHOD EmailNotifier#sendCancellation notifications/src/main/java/shop/notifications/EmailNotifier.java:12
|
||||
METHOD EmailNotifier#send notifications/src/main/java/shop/notifications/EmailNotifier.java:16
|
||||
TYPE Order orders/src/main/java/shop/orders/Order.java:7
|
||||
TYPE OrderRepository orders/src/main/java/shop/orders/OrderRepository.java:8
|
||||
METHOD OrderRepository#save orders/src/main/java/shop/orders/OrderRepository.java:13
|
||||
METHOD OrderRepository#findById orders/src/main/java/shop/orders/OrderRepository.java:19
|
||||
TYPE OrderService orders/src/main/java/shop/orders/OrderService.java:11
|
||||
METHOD OrderService#OrderService orders/src/main/java/shop/orders/OrderService.java:18
|
||||
METHOD OrderService#placeOrder orders/src/main/java/shop/orders/OrderService.java:27
|
||||
METHOD OrderService#cancelOrder orders/src/main/java/shop/orders/OrderService.java:38
|
||||
TYPE CardGateway payments/src/main/java/shop/payments/CardGateway.java:6
|
||||
METHOD CardGateway#authorize payments/src/main/java/shop/payments/CardGateway.java:9
|
||||
METHOD CardGateway#reverse payments/src/main/java/shop/payments/CardGateway.java:12
|
||||
TYPE PaymentService payments/src/main/java/shop/payments/PaymentService.java:6
|
||||
METHOD PaymentService#PaymentService payments/src/main/java/shop/payments/PaymentService.java:10
|
||||
METHOD PaymentService#charge payments/src/main/java/shop/payments/PaymentService.java:15
|
||||
METHOD PaymentService#refund payments/src/main/java/shop/payments/PaymentService.java:23
|
||||
@@ -0,0 +1,29 @@
|
||||
# search_code ranking with the hashing-512 embedder (top 3 per query)
|
||||
|
||||
## query: charge the customer's card
|
||||
0.607 PaymentService#charge payments/src/main/java/shop/payments/PaymentService.java:15
|
||||
0.532 PaymentService payments/src/main/java/shop/payments/PaymentService.java:6
|
||||
0.427 PaymentService#refund payments/src/main/java/shop/payments/PaymentService.java:23
|
||||
|
||||
## query: take units off the shelf for an order
|
||||
0.456 InventoryService#reserve inventory/src/main/java/shop/inventory/InventoryService.java:13
|
||||
0.345 OrderService#cancelOrder orders/src/main/java/shop/orders/OrderService.java:38
|
||||
0.330 OrderRepository#save orders/src/main/java/shop/orders/OrderRepository.java:13
|
||||
|
||||
## query: email the customer that the order was cancelled
|
||||
0.489 EmailNotifier#sendCancellation notifications/src/main/java/shop/notifications/EmailNotifier.java:12
|
||||
0.466 Order orders/src/main/java/shop/orders/Order.java:7
|
||||
0.466 EmailNotifier#sendConfirmation notifications/src/main/java/shop/notifications/EmailNotifier.java:7
|
||||
|
||||
## query: find an order by its id
|
||||
0.741 OrderRepository#findById orders/src/main/java/shop/orders/OrderRepository.java:19
|
||||
0.424 OrderRepository#save orders/src/main/java/shop/orders/OrderRepository.java:13
|
||||
0.387 OrderService#cancelOrder orders/src/main/java/shop/orders/OrderService.java:38
|
||||
|
||||
## query: return money to the customer
|
||||
0.406 PaymentService#refund payments/src/main/java/shop/payments/PaymentService.java:23
|
||||
0.227 CardGateway#authorize payments/src/main/java/shop/payments/CardGateway.java:9
|
||||
0.224 PaymentService#charge payments/src/main/java/shop/payments/PaymentService.java:15
|
||||
|
||||
## the limit: a query that shares no words with the code
|
||||
query: chargeback -> 0 result(s)
|
||||
@@ -0,0 +1,23 @@
|
||||
# find_usages for OrderRepository#save: name match vs resolved
|
||||
|
||||
## name match only (resolve=false): 3 usages
|
||||
inventory/src/main/java/shop/inventory/InventoryService.java:18 in InventoryService#reserve [not confirmed by the solver]
|
||||
stock.save(new StockItem(sku, item.onHand() - units));
|
||||
inventory/src/main/java/shop/inventory/InventoryService.java:24 in InventoryService#release [not confirmed by the solver]
|
||||
stock.save(new StockItem(sku, item.onHand() + units));
|
||||
orders/src/main/java/shop/orders/OrderService.java:31 in OrderService#placeOrder [not confirmed by the solver]
|
||||
Order order = orders.save(new Order("ord-" + skus.hashCode(), customerId, skus, total));
|
||||
|
||||
## resolved (resolve=true): 1 usage
|
||||
orders/src/main/java/shop/orders/OrderService.java:31 in OrderService#placeOrder
|
||||
Order order = orders.save(new Order("ord-" + skus.hashCode(), customerId, skus, total));
|
||||
|
||||
## the other save, InventoryRepository#save, resolved: 2 usages
|
||||
inventory/src/main/java/shop/inventory/InventoryService.java:18 in InventoryService#reserve
|
||||
stock.save(new StockItem(sku, item.onHand() - units));
|
||||
inventory/src/main/java/shop/inventory/InventoryService.java:24 in InventoryService#release
|
||||
stock.save(new StockItem(sku, item.onHand() + units));
|
||||
|
||||
## a call through an interface, CardGateway#authorize, resolved: 1 usage
|
||||
payments/src/main/java/shop/payments/PaymentService.java:19 in PaymentService#charge
|
||||
return gateway.authorize(customerId, amount);
|
||||
@@ -0,0 +1,17 @@
|
||||
# find_usages for a type, and for a library that is not in the monorepo
|
||||
|
||||
## PaymentService (resolved): 2 usages
|
||||
orders/src/main/java/shop/orders/OrderService.java:15 in OrderService#(type level)
|
||||
private final PaymentService payments;
|
||||
orders/src/main/java/shop/orders/OrderService.java:18 in OrderService#OrderService
|
||||
public OrderService(OrderRepository orders, InventoryService inventory, PaymentService payments, EmailNotifier notifier)
|
||||
|
||||
## AuditClient#record (resolved): the class lives in a library outside the monorepo
|
||||
notifications/src/main/java/shop/notifications/AuditTrail.java:16 in AuditTrail#recordEmail [not confirmed by the solver]
|
||||
client.record("email", customerId, subject);
|
||||
not confirmed by the solver: 1
|
||||
|
||||
## PaymentService#refund (resolved): the call passes order.customerId(), an implicit record accessor
|
||||
orders/src/main/java/shop/orders/OrderService.java:43 in OrderService#cancelOrder [not confirmed by the solver]
|
||||
payments.refund(order.customerId(), order.total());
|
||||
not confirmed by the solver: 1
|
||||
@@ -0,0 +1,23 @@
|
||||
# code-search-mcp over HTTP, 2026-07-28: no handshake, no session
|
||||
|
||||
## 1. tools/list: the names and input schemas the model will see
|
||||
< 200
|
||||
search_code readOnlyHint=true
|
||||
Find classes and methods by what they do. Ranks by similarity to the query, so describe behaviour rather than guessing an exact name. Use find_usages for callers.
|
||||
find_usages readOnlyHint=true
|
||||
List every place a class or method is used, with file, line and the calling method.
|
||||
get_source readOnlyHint=true
|
||||
Return the source of one method, so the model reads the body only when it needs it.
|
||||
|
||||
## 2. tools/call search_code sent to instance A
|
||||
> POST /mcp
|
||||
> MCP-Protocol-Version: 2026-07-28
|
||||
> Mcp-Method: tools/call
|
||||
> Mcp-Name: search_code
|
||||
> {"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"search_code","arguments":{"query":"charge the customer's card","k":2},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientInfo":{"name":"wire-test","version":"1"},"io.modelcontextprotocol/clientCapabilities":{}}}}
|
||||
< 200
|
||||
< {"jsonrpc":"2.0","id":2,"result":{"content":[{"type":"text","text":"1. 0.607 PaymentService#charge payments/src/main/java/shop/payments/PaymentService.java:15\n public String charge(String customerId, BigDecimal amount)\n // Charges the customer's card for the given amount and returns the receipt id.\n2. 0.532 PaymentService payments/src/main/java/shop/payments/PaymentService.java:6\n class PaymentService\n // Takes payments from customers and refunds them, through a card gateway."}],"resultType":"complete","_meta":{"io.modelcontextprotocol/serverInfo":{"name":"code-search-mcp","version":"1.0.0"}}}}
|
||||
|
||||
## 3. the same call sent to instance B, a separate server that never saw request 2
|
||||
< 200
|
||||
same answer text as instance A: true
|
||||
@@ -0,0 +1,36 @@
|
||||
# How a malformed request fails
|
||||
|
||||
## 1. Mcp-Method header missing
|
||||
> POST /mcp
|
||||
> MCP-Protocol-Version: 2026-07-28
|
||||
> Mcp-Name: search_code
|
||||
> {"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"search_code","arguments":{"query":"refund"},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientInfo":{"name":"wire-test","version":"1"},"io.modelcontextprotocol/clientCapabilities":{}}}}
|
||||
< 400
|
||||
< {"jsonrpc":"2.0","id":7,"error":{"code":-32020,"message":"Missing required header: Mcp-Method"}}
|
||||
|
||||
## 2. Mcp-Name header says find_usages but the body calls search_code
|
||||
> POST /mcp
|
||||
> MCP-Protocol-Version: 2026-07-28
|
||||
> Mcp-Method: tools/call
|
||||
> Mcp-Name: find_usages
|
||||
> {"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"search_code","arguments":{"query":"refund"},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientInfo":{"name":"wire-test","version":"1"},"io.modelcontextprotocol/clientCapabilities":{}}}}
|
||||
< 400
|
||||
< {"jsonrpc":"2.0","id":7,"error":{"code":-32020,"message":"Mcp-Name header does not match request name/uri"}}
|
||||
|
||||
## 3. a client still speaking 2025-11-25
|
||||
> POST /mcp
|
||||
> MCP-Protocol-Version: 2025-11-25
|
||||
> Mcp-Method: tools/call
|
||||
> Mcp-Name: search_code
|
||||
> {"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"search_code","arguments":{"query":"refund"},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientInfo":{"name":"wire-test","version":"1"},"io.modelcontextprotocol/clientCapabilities":{}}}}
|
||||
< 400
|
||||
< {"jsonrpc":"2.0","id":7,"error":{"code":-32020,"message":"MCP-Protocol-Version header does not match _meta protocol version"}}
|
||||
|
||||
## 4. _meta without clientCapabilities
|
||||
> POST /mcp
|
||||
> MCP-Protocol-Version: 2026-07-28
|
||||
> Mcp-Method: tools/call
|
||||
> Mcp-Name: search_code
|
||||
> {"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"search_code","arguments":{"query":"refund"},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientInfo":{"name":"wire-test","version":"1"}}}}
|
||||
< 400
|
||||
< {"jsonrpc":"2.0","id":7,"error":{"code":-32602,"message":"_meta['io.modelcontextprotocol/clientCapabilities'] is required"}}
|
||||
@@ -0,0 +1,29 @@
|
||||
# An agent's session through the 2.2.0 SDK client: search, then callers, then source
|
||||
|
||||
## search_code {query: return money to the customer, k: 2}
|
||||
1. 0.406 PaymentService#refund payments/src/main/java/shop/payments/PaymentService.java:23
|
||||
public String refund(String customerId, BigDecimal amount)
|
||||
// Returns money to the customer's card after a cancelled order.
|
||||
2. 0.227 CardGateway#authorize payments/src/main/java/shop/payments/CardGateway.java:9
|
||||
abstract String authorize(String customerId, BigDecimal amount)
|
||||
// Asks the processor to take the amount from the customer's card. Returns a receipt id.
|
||||
|
||||
## find_usages {symbol: PaymentService#refund}
|
||||
1 usage(s) of PaymentService#refund (resolved)
|
||||
orders/src/main/java/shop/orders/OrderService.java:43 in OrderService#cancelOrder [unresolved: matched by name]
|
||||
payments.refund(order.customerId(), order.total());
|
||||
1 of these could not be resolved by the symbol solver; check them by hand
|
||||
|
||||
## get_source {name: OrderService#cancelOrder}
|
||||
// orders/src/main/java/shop/orders/OrderService.java:38
|
||||
/**
|
||||
* Cancels an order, puts the stock back on the shelf and returns the money to the customer.
|
||||
*/
|
||||
public void cancelOrder(String orderId) {
|
||||
Order order = orders.findById(orderId).orElseThrow();
|
||||
for (String sku : order.skus()) {
|
||||
inventory.release(sku, 1);
|
||||
}
|
||||
payments.refund(order.customerId(), order.total());
|
||||
notifier.sendCancellation(order.customerId(), orderId);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
# Tool failures are results with isError=true, not protocol errors
|
||||
|
||||
## get_source with a name that does not exist
|
||||
isError=true
|
||||
no class or method called 'PaymentService#chargeback'. Use search_code to find the exact name.
|
||||
|
||||
## search_code with a blank query
|
||||
isError=true
|
||||
'query' is required and must be a non-empty string
|
||||
|
||||
## search_code that matches nothing (not an error: an empty answer with advice)
|
||||
isError=false
|
||||
no matches for 'chargeback' (the hashing-512 embedder matches words, so try other words from the code's vocabulary)
|
||||
@@ -0,0 +1,5 @@
|
||||
# OpenAiCompatibleEmbedder against a stub /v1/embeddings server
|
||||
requests sent for 70 texts: 2
|
||||
first request: Bearer secret-key | {"model":"nomic-embed-text","input":["text 0","text 1","te...
|
||||
vectors returned: 70, each normalised to length 1: true
|
||||
text 5 got the vector the stub built for index 5: true
|
||||
@@ -0,0 +1,12 @@
|
||||
# java -jar target/code-search-mcp.jar sample-monorepo 8791, then curl
|
||||
[main] WARN io.modelcontextprotocol.modern.server.HmacRequestStateCodec - HmacRequestStateCodec: no key configured, generated a random per-process key. State sealed by this instance cannot be opened by another instance; configure a shared key for multi-instance deployments.
|
||||
indexed 30 units from sample-monorepo with the hashing-512 embedder
|
||||
serving MCP 2026-07-28 at http://127.0.0.1:<port>/mcp
|
||||
|
||||
$ curl ... -H "Mcp-Method: tools/call" -H "Mcp-Name: search_code" -d {"query":"cancel an order","k":2}
|
||||
1. 0.844 OrderService#cancelOrder orders/src/main/java/shop/orders/OrderService.java:38
|
||||
public void cancelOrder(String orderId)
|
||||
// Cancels an order, puts the stock back on the shelf and returns the money to the customer.
|
||||
2. 0.541 OrderService orders/src/main/java/shop/orders/OrderService.java:11
|
||||
class OrderService
|
||||
// Places and cancels customer orders by coordinating stock, payment and email.
|
||||
Reference in New Issue
Block a user