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:
Ankur
2026-11-25 13:29:50 +05:30
co-authored by Claude Sonnet 5.5
parent 26e0a3875a
commit e116c4d5a4
45 changed files with 2002 additions and 0 deletions
@@ -0,0 +1,21 @@
package shop.inventory;
import java.util.HashMap;
import java.util.Map;
/** Keeps stock levels in memory. */
public class InventoryRepository {
private final Map<String, StockItem> bySku = new HashMap<>();
/** Stores the stock level for a product, replacing the earlier value. */
public StockItem save(StockItem item) {
bySku.put(item.sku(), item);
return item;
}
/** Returns the stock level for a product, or zero units when the product is unknown. */
public StockItem get(String sku) {
return bySku.getOrDefault(sku, new StockItem(sku, 0));
}
}
@@ -0,0 +1,26 @@
package shop.inventory;
/** Reserves and releases units of stock so the shop never sells what it does not have. */
public class InventoryService {
private final InventoryRepository stock;
public InventoryService(InventoryRepository stock) {
this.stock = stock;
}
/** Takes units off the shelf for an order. Fails when there is not enough stock. */
public void reserve(String sku, int units) {
StockItem item = stock.get(sku);
if (item.onHand() < units) {
throw new IllegalStateException("out of stock: " + sku);
}
stock.save(new StockItem(sku, item.onHand() - units));
}
/** Puts units back on the shelf, for example after a cancelled order. */
public void release(String sku, int units) {
StockItem item = stock.get(sku);
stock.save(new StockItem(sku, item.onHand() + units));
}
}
@@ -0,0 +1,5 @@
package shop.inventory;
/** How many units of one product are on the shelf. */
public record StockItem(String sku, int onHand) {
}
@@ -0,0 +1,18 @@
package shop.notifications;
import com.acme.audit.AuditClient;
/** Records who was emailed what. The audit client is a company library that is not part of this monorepo. */
public class AuditTrail {
private final AuditClient client;
public AuditTrail(AuditClient client) {
this.client = client;
}
/** Writes one audit record for an email that was sent. */
public void recordEmail(String customerId, String subject) {
client.record("email", customerId, subject);
}
}
@@ -0,0 +1,19 @@
package shop.notifications;
/** Sends transactional emails to customers. */
public class EmailNotifier {
/** Emails the customer that their order was placed. */
public void sendConfirmation(String customerId, String orderId) {
send(customerId, "Order " + orderId + " confirmed");
}
/** Emails the customer that their order was cancelled and the money is on its way back. */
public void sendCancellation(String customerId, String orderId) {
send(customerId, "Order " + orderId + " cancelled");
}
private void send(String customerId, String subject) {
System.out.println("mail to " + customerId + ": " + subject);
}
}
@@ -0,0 +1,8 @@
package shop.orders;
import java.math.BigDecimal;
import java.util.List;
/** A customer order: the lines being bought and the total the customer will be charged. */
public record Order(String id, String customerId, List<String> skus, BigDecimal total) {
}
@@ -0,0 +1,22 @@
package shop.orders;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
/** Keeps orders in memory. A real service would sit on a database. */
public class OrderRepository {
private final Map<String, Order> byId = new HashMap<>();
/** Stores the order, replacing any earlier version with the same id. */
public Order save(Order order) {
byId.put(order.id(), order);
return order;
}
/** Looks an order up by its id. */
public Optional<Order> findById(String id) {
return Optional.ofNullable(byId.get(id));
}
}
@@ -0,0 +1,46 @@
package shop.orders;
import java.math.BigDecimal;
import java.util.List;
import shop.inventory.InventoryService;
import shop.notifications.EmailNotifier;
import shop.payments.PaymentService;
/** Places and cancels customer orders by coordinating stock, payment and email. */
public class OrderService {
private final OrderRepository orders;
private final InventoryService inventory;
private final PaymentService payments;
private final EmailNotifier notifier;
public OrderService(OrderRepository orders, InventoryService inventory, PaymentService payments,
EmailNotifier notifier) {
this.orders = orders;
this.inventory = inventory;
this.payments = payments;
this.notifier = notifier;
}
/** Reserves stock, charges the customer's card and emails a confirmation. */
public Order placeOrder(String customerId, List<String> skus, BigDecimal total) {
for (String sku : skus) {
inventory.reserve(sku, 1);
}
Order order = orders.save(new Order("ord-" + skus.hashCode(), customerId, skus, total));
payments.charge(customerId, total);
notifier.sendConfirmation(customerId, order.id());
return order;
}
/** 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 @@
package shop.payments;
import java.math.BigDecimal;
/** The boundary to the external card processor. */
public interface CardGateway {
/** Asks the processor to take the amount from the customer's card. Returns a receipt id. */
String authorize(String customerId, BigDecimal amount);
/** Asks the processor to give the amount back to the customer's card. Returns a receipt id. */
String reverse(String customerId, BigDecimal amount);
}
@@ -0,0 +1,26 @@
package shop.payments;
import java.math.BigDecimal;
/** Takes payments from customers and refunds them, through a card gateway. */
public class PaymentService {
private final CardGateway gateway;
public PaymentService(CardGateway gateway) {
this.gateway = gateway;
}
/** Charges the customer's card for the given amount and returns the receipt id. */
public String charge(String customerId, BigDecimal amount) {
if (amount.signum() <= 0) {
throw new IllegalArgumentException("amount must be positive");
}
return gateway.authorize(customerId, amount);
}
/** Returns money to the customer's card after a cancelled order. */
public String refund(String customerId, BigDecimal amount) {
return gateway.reverse(customerId, amount);
}
}