You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2026/01/15 14:40:14 UTC
(sling-org-apache-sling-mcp-server) 08/27: feat(mcp): expose the recent requests data as a resource
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-org-apache-sling-mcp-server.git
commit a361f5a1ac7665999b4aef966183211108419384
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Dec 10 15:52:01 2025 +0100
feat(mcp): expose the recent requests data as a resource
---
pom.xml | 6 ++
.../impl/contribs/RecentRequestsContribution.java | 73 ++++++++++++++++++++++
2 files changed, 79 insertions(+)
diff --git a/pom.xml b/pom.xml
index 4a2323c..e41f259 100644
--- a/pom.xml
+++ b/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/src/main/java/org/apache/sling/mcp/server/impl/contribs/RecentRequestsContribution.java b/src/main/java/org/apache/sling/mcp/server/impl/contribs/RecentRequestsContribution.java
new file mode 100644
index 0000000..53a127e
--- /dev/null
+++ b/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)));
+ }));
+ }
+}