Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/main/java/io/naftiko/Capability.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
import io.naftiko.engine.ExternalRefResolver;
import io.naftiko.spec.ExecutionContext;
import io.naftiko.engine.consumes.ClientAdapter;
import io.naftiko.engine.consumes.HttpClientAdapter;
import io.naftiko.engine.exposes.ApiServerAdapter;
import io.naftiko.engine.exposes.McpServerAdapter;
import io.naftiko.engine.consumes.http.HttpClientAdapter;
import io.naftiko.engine.exposes.ServerAdapter;
import io.naftiko.engine.exposes.SkillServerAdapter;
import io.naftiko.engine.exposes.mcp.McpServerAdapter;
import io.naftiko.engine.exposes.rest.RestServerAdapter;
import io.naftiko.engine.exposes.skill.SkillServerAdapter;
import io.naftiko.spec.NaftikoSpec;
import io.naftiko.spec.consumes.ClientSpec;
import io.naftiko.spec.consumes.HttpClientSpec;
import io.naftiko.spec.exposes.ApiServerSpec;
import io.naftiko.spec.exposes.McpServerSpec;
import io.naftiko.spec.consumes.http.HttpClientSpec;
import io.naftiko.spec.exposes.ServerSpec;
import io.naftiko.spec.exposes.SkillServerSpec;
import io.naftiko.spec.exposes.mcp.McpServerSpec;
import io.naftiko.spec.exposes.rest.RestServerSpec;
import io.naftiko.spec.exposes.skill.SkillServerSpec;

/**
* Main Capability class that initializes and manages adapters based on configuration
Expand Down Expand Up @@ -86,8 +86,8 @@ public String getVariable(String key) {
}

for (ServerSpec serverSpec : spec.getCapability().getExposes()) {
if ("api".equals(serverSpec.getType())) {
this.serverAdapters.add(new ApiServerAdapter(this, (ApiServerSpec) serverSpec));
if ("rest".equals(serverSpec.getType())) {
this.serverAdapters.add(new RestServerAdapter(this, (RestServerSpec) serverSpec));
} else if ("mcp".equals(serverSpec.getType())) {
this.serverAdapters.add(new McpServerAdapter(this, (McpServerSpec) serverSpec));
} else if ("skill".equals(serverSpec.getType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.naftiko.Capability;
import io.naftiko.engine.Adapter;
import io.naftiko.spec.consumes.ClientSpec;
import io.naftiko.spec.consumes.HttpClientSpec;
import io.naftiko.spec.consumes.http.HttpClientSpec;

/**
* Client Adapter implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.naftiko.engine.consumes;
package io.naftiko.engine.consumes.http;

import org.restlet.Client;
import org.restlet.Request;
import org.restlet.data.ChallengeResponse;
import org.restlet.data.ChallengeScheme;
import io.naftiko.Capability;
import io.naftiko.engine.Resolver;
import io.naftiko.engine.consumes.ClientAdapter;
import io.naftiko.spec.InputParameterSpec;
import io.naftiko.spec.consumes.ApiKeyAuthenticationSpec;
import io.naftiko.spec.consumes.AuthenticationSpec;
import io.naftiko.spec.consumes.BasicAuthenticationSpec;
import io.naftiko.spec.consumes.BearerAuthenticationSpec;
import io.naftiko.spec.consumes.DigestAuthenticationSpec;
import io.naftiko.spec.consumes.HttpClientOperationSpec;
import io.naftiko.spec.consumes.HttpClientResourceSpec;
import io.naftiko.spec.consumes.HttpClientSpec;
import io.naftiko.spec.consumes.http.HttpApiKeyAuthenticationSpec;
import io.naftiko.spec.consumes.http.HttpAuthenticationSpec;
import io.naftiko.spec.consumes.http.HttpBasicAuthenticationSpec;
import io.naftiko.spec.consumes.http.HttpBearerAuthenticationSpec;
import io.naftiko.spec.consumes.http.HttpDigestAuthenticationSpec;
import io.naftiko.spec.consumes.http.HttpClientOperationSpec;
import io.naftiko.spec.consumes.http.HttpClientResourceSpec;
import io.naftiko.spec.consumes.http.HttpClientSpec;
import static org.restlet.data.Protocol.HTTP;
import static org.restlet.data.Protocol.HTTPS;
import java.util.Map;
Expand Down Expand Up @@ -84,7 +85,7 @@ public void setHeaders(Request request) {
*/
public void setChallengeResponse(Request serverRequest, Request clientRequest, String targetRef,
Map<String, Object> parameters) {
AuthenticationSpec authenticationSpec = getHttpClientSpec().getAuthentication();
HttpAuthenticationSpec authenticationSpec = getHttpClientSpec().getAuthentication();

if (authenticationSpec != null) {
// Add authentication headers if needed
Expand All @@ -93,8 +94,8 @@ public void setChallengeResponse(Request serverRequest, Request clientRequest, S

switch (type) {
case "basic":
BasicAuthenticationSpec basicAuth =
(BasicAuthenticationSpec) authenticationSpec;
HttpBasicAuthenticationSpec basicAuth =
(HttpBasicAuthenticationSpec) authenticationSpec;
challengeResponse = new ChallengeResponse(ChallengeScheme.HTTP_BASIC);
challengeResponse.setIdentifier(
Resolver.resolveMustacheTemplate(basicAuth.getUsername(), parameters));
Expand All @@ -105,8 +106,8 @@ public void setChallengeResponse(Request serverRequest, Request clientRequest, S
break;

case "digest":
DigestAuthenticationSpec digestAuth =
(DigestAuthenticationSpec) authenticationSpec;
HttpDigestAuthenticationSpec digestAuth =
(HttpDigestAuthenticationSpec) authenticationSpec;
challengeResponse = new ChallengeResponse(ChallengeScheme.HTTP_DIGEST);
challengeResponse.setIdentifier(
Resolver.resolveMustacheTemplate(digestAuth.getUsername(), parameters));
Expand All @@ -116,17 +117,17 @@ public void setChallengeResponse(Request serverRequest, Request clientRequest, S
break;

case "bearer":
BearerAuthenticationSpec bearerAuth =
(BearerAuthenticationSpec) authenticationSpec;
HttpBearerAuthenticationSpec bearerAuth =
(HttpBearerAuthenticationSpec) authenticationSpec;
challengeResponse = new ChallengeResponse(ChallengeScheme.HTTP_OAUTH_BEARER);
challengeResponse.setRawValue(
Resolver.resolveMustacheTemplate(bearerAuth.getToken(), parameters));
clientRequest.setChallengeResponse(challengeResponse);
break;

case "apikey":
ApiKeyAuthenticationSpec apiKeyAuth =
(ApiKeyAuthenticationSpec) authenticationSpec;
HttpApiKeyAuthenticationSpec apiKeyAuth =
(HttpApiKeyAuthenticationSpec) authenticationSpec;
String key = Resolver.resolveMustacheTemplate(apiKeyAuth.getKey(), parameters);
String value =
Resolver.resolveMustacheTemplate(apiKeyAuth.getValue(), parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.naftiko.engine.consumes;
package io.naftiko.engine.consumes.http;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
* HTTP Operation representation
*/
public class Operation {
public class HttpOperation {

private volatile String httpMethod;

private volatile String targetUri;

private List<Parameter> parameters;
private List<HttpParameter> parameters;

private final List<Response> responses;
private final List<HttpResponse> responses;

public Operation() {
public HttpOperation() {
super();
this.httpMethod = null;
this.targetUri = null;
this.parameters = new CopyOnWriteArrayList<>();
this.responses = new CopyOnWriteArrayList<>();
}

public List<Parameter> getParameters() {
public List<HttpParameter> getParameters() {
return parameters;
}

Expand All @@ -49,7 +49,7 @@ public String getTargetUri() {
return targetUri;
}

public List<Response> getResponses() {
public List<HttpResponse> getResponses() {
return this.responses;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.naftiko.engine.consumes;
package io.naftiko.engine.consumes.http;

/**
* HTTP Parameter representation
*/
public class Parameter {
public class HttpParameter {

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.naftiko.engine.consumes;
package io.naftiko.engine.consumes.http;

import java.util.List;

/**
* HTTP Response representation
*/
public class Response {
public class HttpResponse {

private List<Parameter> parameters;
private List<HttpParameter> parameters;

public Response() {
public HttpResponse() {
super();
}

public List<Parameter> getParameters() {
public List<HttpParameter> getParameters() {
return parameters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.naftiko.engine;
package io.naftiko.engine.exposes;

import java.util.Iterator;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.naftiko.Capability;
import io.naftiko.engine.LookupExecutor;
import io.naftiko.engine.Resolver;
import io.naftiko.engine.StepExecutionContext;
import io.naftiko.engine.consumes.ClientAdapter;
import io.naftiko.engine.consumes.HttpClientAdapter;
import io.naftiko.engine.consumes.http.HttpClientAdapter;
import io.naftiko.spec.InputParameterSpec;
import io.naftiko.spec.OutputParameterSpec;
import io.naftiko.spec.consumes.HttpClientOperationSpec;
import io.naftiko.spec.consumes.http.HttpClientOperationSpec;
import io.naftiko.spec.exposes.ServerCallSpec;
import io.naftiko.spec.exposes.ApiServerOperationSpec;
import io.naftiko.spec.exposes.ApiServerResourceSpec;
import io.naftiko.spec.exposes.ApiServerSpec;
import io.naftiko.spec.exposes.rest.RestServerOperationSpec;
import io.naftiko.spec.exposes.rest.RestServerResourceSpec;
import io.naftiko.spec.exposes.rest.RestServerSpec;
import io.naftiko.spec.exposes.OperationStepSpec;
import io.naftiko.spec.exposes.OperationStepCallSpec;
import io.naftiko.spec.exposes.OperationStepLookupSpec;
Expand All @@ -53,7 +52,7 @@
* - Finding the appropriate client adapter and operation
* - Executing the client request
*
* Used by both ApiResourceRestlet and McpToolHandler to avoid duplication.
* Used by both RestResourceRestlet and McpToolHandler to avoid duplication.
*/
public class OperationStepExecutor {

Expand All @@ -70,8 +69,8 @@ public OperationStepExecutor(Capability capability) {
* server-level, resource-level and operation-level InputParameterSpec entries.
*/
public Map<String, Object> resolveInputParametersFromRequest(Request request,
ApiServerSpec serverSpec, ApiServerResourceSpec resourceSpec,
ApiServerOperationSpec serverOp) {
RestServerSpec serverSpec, RestServerResourceSpec resourceSpec,
RestServerOperationSpec serverOp) {
Map<String, Object> params = new ConcurrentHashMap<>();
JsonNode tmpRoot = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.naftiko.engine.exposes;
package io.naftiko.engine.exposes.mcp;

import java.io.IOException;
import java.net.URI;
Expand All @@ -25,8 +25,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.naftiko.spec.exposes.McpPromptMessageSpec;
import io.naftiko.spec.exposes.McpServerPromptSpec;
import io.naftiko.spec.exposes.mcp.McpPromptMessageSpec;
import io.naftiko.spec.exposes.mcp.McpServerPromptSpec;

/**
* Handles MCP {@code prompts/get} requests by rendering prompt templates.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.naftiko.engine.exposes;
package io.naftiko.engine.exposes.mcp;

import java.util.List;
import java.util.Map;
Expand All @@ -23,9 +23,9 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.modelcontextprotocol.spec.McpSchema;
import io.naftiko.spec.exposes.McpPromptArgumentSpec;
import io.naftiko.spec.exposes.McpServerPromptSpec;
import io.naftiko.spec.exposes.McpServerResourceSpec;
import io.naftiko.spec.exposes.mcp.McpPromptArgumentSpec;
import io.naftiko.spec.exposes.mcp.McpServerPromptSpec;
import io.naftiko.spec.exposes.mcp.McpServerResourceSpec;

/**
* Transport-agnostic MCP JSON-RPC protocol dispatcher.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.naftiko.engine.exposes;
package io.naftiko.engine.exposes.mcp;

import java.io.IOException;
import java.net.URI;
Expand All @@ -28,7 +28,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.naftiko.Capability;
import io.naftiko.spec.exposes.McpServerResourceSpec;
import io.naftiko.engine.exposes.OperationStepExecutor;
import io.naftiko.spec.exposes.mcp.McpServerResourceSpec;

/**
* Handles MCP resource reads by serving either dynamic (HTTP-backed) or static (file-backed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.naftiko.engine.exposes;
package io.naftiko.engine.exposes.mcp;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -24,9 +24,10 @@
import org.restlet.Context;
import io.modelcontextprotocol.spec.McpSchema;
import io.naftiko.Capability;
import io.naftiko.engine.exposes.ServerAdapter;
import io.naftiko.spec.InputParameterSpec;
import io.naftiko.spec.exposes.McpServerSpec;
import io.naftiko.spec.exposes.McpServerToolSpec;
import io.naftiko.spec.exposes.mcp.McpServerSpec;
import io.naftiko.spec.exposes.mcp.McpServerToolSpec;

/**
* MCP Server Adapter implementation.
Expand All @@ -46,7 +47,7 @@ public class McpServerAdapter extends ServerAdapter {
private Server jettyServer;

/** Stdio handler and thread — only initialized for stdio transport */
private volatile StdioJsonRpcHandler stdioHandler;
private volatile McpStdioHandler stdioHandler;
private volatile Thread stdioThread;

private final McpToolHandler toolHandler;
Expand Down Expand Up @@ -102,15 +103,15 @@ private void initHttpTransport(McpServerSpec serverSpec) {
jettyServer.addConnector(connector);

// Set the MCP handler
jettyServer.setHandler(new JettyMcpStreamableHandler(this));
jettyServer.setHandler(new McpStreamableHandler(this));
}

/**
* Initialize the stdio transport (stdin/stdout JSON-RPC).
*/
private void initStdioTransport() {
McpProtocolDispatcher dispatcher = new McpProtocolDispatcher(this);
this.stdioHandler = new StdioJsonRpcHandler(dispatcher);
this.stdioHandler = new McpStdioHandler(dispatcher);
}

/**
Expand Down
Loading
Loading