Publish Workflow API Services¶
Publish a workflow as a dynamic API service (dynamic_service) bound to an HTML interaction page stored in a workspace volume for clients that support MCP Apps.
Task flow¶
Upload the interactive HTML file to a workspace volume and obtain its file ID (
HTML_FILE_ID).Prepare a tested native MOWL workflow definition together with JSON Schema files matching its inputs and outputs.
Deploy the workflow in
dynamic_servicemode with the service name, input and output schemas, result mode, and HTML UI resource reference.Save the returned workflow ID and inspect any deployment warnings; include the UI resource reference again whenever updating the dynamic service configuration to retain the page binding.
Prerequisites¶
Complete the endpoint, personal access token, and workspace setup in Use the SDK.
Workflow definition and schemas (
WORKFLOW_FILE,INPUT_SCHEMA_FILE,OUTPUT_SCHEMA_FILE): prepare a tested native MOWL JSON file and JSON Schema files matching the workflow’s inputs and outputs.HTML file ID and existing workflow ID: upload the HTML file to a workspace volume as shown in Manage Volumes and Files and save the returned file ID (
HTML_FILE_ID). When updating an existing service, obtain its workflow ID (WORKFLOW_ID) as shown in Read Resource Inventories.
Publish the dynamic service¶
Pass the workflow definition, input and output JSON Schema contents, and HTML file ID to deploy the service. Leave WORKFLOW_ID unset when publishing a new service.
import json
import os
from pathlib import Path
import moi_product_sdk as sdk
client = sdk.new_with_personal_access_token(
os.environ["PRODUCT_API_BASE_URL"], os.environ["PRODUCT_API_KEY"]
)
workspace = client.workspace(os.environ["WORKSPACE_ID"])
definition = json.loads(Path(os.environ["WORKFLOW_FILE"]).read_text())
workflow, deployment = workspace.deploy_workflow(
"Document service", "", os.environ.get("WORKFLOW_ID", ""),
sdk.with_workflow_mowl(definition),
sdk.with_workflow_execution_mode("dynamic_service"),
sdk.with_workflow_dynamic_service(
service_name="document_service",
input_schema=Path(os.environ["INPUT_SCHEMA_FILE"]).read_text(),
output_schema=Path(os.environ["OUTPUT_SCHEMA_FILE"]).read_text(),
result_mode="oneshot",
ui_resource={"file_id": os.environ["HTML_FILE_ID"], "mime_type": "text/html"},
),
)
print("Workflow:", workflow.id)
print("Warnings:", deployment.warnings)
package main
import (
"context"
"encoding/json"
"fmt"
"os"
sdk "github.com/matrixorigin/matrixflow/sdk/go-sdk"
)
func main() {
ctx := context.Background()
client, err := sdk.NewWithPersonalAccessToken(
os.Getenv("PRODUCT_API_BASE_URL"),
os.Getenv("PRODUCT_API_KEY"),
)
if err != nil {
panic(err)
}
workspace, err := client.Workspace(os.Getenv("WORKSPACE_ID"))
if err != nil {
panic(err)
}
definition, err := os.ReadFile(os.Getenv("WORKFLOW_FILE"))
if err != nil {
panic(err)
}
inputSchema, err := os.ReadFile(os.Getenv("INPUT_SCHEMA_FILE"))
if err != nil {
panic(err)
}
outputSchema, err := os.ReadFile(os.Getenv("OUTPUT_SCHEMA_FILE"))
if err != nil {
panic(err)
}
workflow, deployment, err := workspace.DeployWorkflow(
ctx,
"Document service",
"",
os.Getenv("WORKFLOW_ID"),
sdk.WithWorkflowMOWL(json.RawMessage(definition)),
sdk.WithWorkflowExecutionMode("dynamic_service"),
sdk.WithWorkflowDynamicService(sdk.WorkflowDynamicServiceParam{
ServiceName: "document_service",
InputSchema: string(inputSchema),
OutputSchema: string(outputSchema),
ResultMode: "oneshot",
UIResource: &sdk.WorkflowUIResourceParam{
FileID: os.Getenv("HTML_FILE_ID"),
MimeType: "text/html",
},
}),
)
if err != nil {
panic(err)
}
fmt.Println("Workflow:", workflow.ID())
fmt.Println("Warnings:", deployment.GetWarnings())
}
Save the returned workflow ID, inspect the workflow details to confirm the dynamic service configuration and invocation endpoint, and verify both a service call and page rendering in your target client. Standard MCP clients that support tool invocation only do not render MCP Apps interaction pages.
Update a page binding¶
When explicitly updating a workflow’s dynamic service configuration, omitting the UI resource clears the existing HTML page binding; include the existing file_id and mime_type whenever you want to retain the bound page. To publish a single operator node as a headless API service, see Manage WorkItem Services.