This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new 1dc46085 feat(mcp): expose the recent requests data as a resource
1dc46085 is described below
commit 1dc4608534712b5d12ff518e31a51d9389aab574
Author: Robert Munteanu <[email protected]>
AuthorDate: Wed Dec 10 15:52:01 2025 +0100
feat(mcp): expose the recent requests data as a resource
---
mcp-server/pom.xml | 6 ++
.../impl/contribs/RecentRequestsContribution.java | 73 ++++++++++++++++++++++
2 files changed, 79 insertions(+)
diff --git a/mcp-server/pom.xml b/mcp-server/pom.xml
index 4a2323c4..e41f259f 100644
--- a/mcp-server/pom.xml
+++ b/mcp-server/pom.xml
@@ -78,6 +78,12 @@
<version>3.0.2</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.engine</artifactId>
+ <version>2.10.2</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
diff --git
a/mcp-server/src/main/java/org/apache/sling/mcp/server/impl/contribs/RecentRequestsContribution.java
b/mcp-server/src/main/java/org/apache/sling/mcp/server/impl/contribs/RecentRequestsContribution.java
new file mode 100644
index 00000000..53a127e3
--- /dev/null
+++
b/mcp-server/src/main/java/org/apache/sling/mcp/server/impl/contribs/RecentRequestsContribution.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.mcp.server.impl.contribs;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+import org.apache.sling.engine.RequestInfo;
+import org.apache.sling.engine.RequestInfoProvider;
+import org.apache.sling.mcp.server.impl.McpServerContribution;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import
io.modelcontextprotocol.server.McpStatelessServerFeatures.SyncResourceSpecification;
+import io.modelcontextprotocol.spec.McpSchema.ReadResourceResult;
+import io.modelcontextprotocol.spec.McpSchema.Resource;
+import io.modelcontextprotocol.spec.McpSchema.TextResourceContents;
+
+@Component
+public class RecentRequestsContribution implements McpServerContribution {
+
+ private RequestInfoProvider requestInfoProvider;
+
+ @Activate
+ public RecentRequestsContribution(@Reference RequestInfoProvider
requestInfoProvider) {
+ this.requestInfoProvider = requestInfoProvider;
+ }
+
+ private String describe(RequestInfo ri) {
+ return "Id: " + ri.getId() + "\n" + "Method: "
+ + ri.getMethod() + "\n" + "Path: " + ri.getPath() + "\n" +
"User id: " + ri.getUserId() + "\n"
+ + ":\n" + ri.getLog();
+ }
+
+ @Override
+ public Optional<SyncResourceSpecification> getSyncResourceSpecification() {
+ return Optional.of(new SyncResourceSpecification(
+ new Resource.Builder()
+ .uri("recent-requests://all")
+ .description("Prints all recent requests ( excluding
/bin/mcp ). Contains information about method, path, user id and a verbose log
of internal operations, including authenticaiton, resource resolution, script
resolution, nested scripts/servlets and filters.")
+ .name("recent-requests-all")
+ .build(),
+ (context, request) -> {
+ String allRequests = StreamSupport.stream(
+
requestInfoProvider.getRequestInfos().spliterator(), false)
+ .filter((ri) -> !ri.getPath().equals("/bin/mcp"))
+ .map(this::describe)
+ .collect(Collectors.joining("\n\n" +
"-".repeat(20) + "\n\n"));
+
+ return new ReadResourceResult(
+ List.of(new
TextResourceContents("recent-requests://all", "text/plain", allRequests)));
+ }));
+ }
+}