AI Application Architecture: Interfaces, MCP Connections, and Skill Packaging

    This article outlines a three-layer architecture for AI applications—interface, connection, and skill—and explains when to use HTML for interaction, how to expose tools through MCP, and how to define, version, and govern reusable skills with clear ownership and acceptance criteria.

    Start by defining what each of the three layers is responsible for

    AI applications typically consist of three types of capabilities. The interface layer presents results to people. The connection layer lets models safely read from and write to external systems. The skill layer turns recurring multi-step operations into reusable units. Only when the boundaries between these three layers are clear can teams divide work effectively and quickly locate the specific layer when problems occur.

    Layer Core responsibility Common technologies Main risks
    Interface layer Present results, collect input, confirm actions HTML, frontend component libraries Page injection, accidental actions without confirmation
    Connection layer Discover tools, pass parameters, return results MCP, REST API Unauthorized calls, key leakage
    Skill layer Encapsulate workflows, fix steps, manage versions Template files, workflow definitions Outdated workflows, lack of maintenance

    HTML interface layer: when to choose it

    HTML is suitable for three types of scenarios: reaching users with zero installation, embedding results in emails, documents, or enterprise portals, and building interfaces that are mainly forms, lists, and charts. HTML generated by an agent has a clear DOM structure that people can read and programs can parse.

    The following table can help with choosing a delivery method.

    Dimension HTML page Native app Mini program (host-app embedded)
    Delivery method Open a link and use it Download and install from an app store Open within a host app
    Release speed Takes effect immediately after deployment Requires review and version release Requires platform review
    Embedding capability Can be embedded in web pages, documents, and messages Mostly limited to within the app Limited to within the host platform
    Hardware and system permissions Limited by the browser; some capabilities require user authorization Can deeply access system capabilities Limited by APIs provided by the platform
    Offline and performance Depends on caching (such as PWA); complex rendering is affected by the device Strong offline capability and controllable performance Between the other two

    When you need continuous background operation, heavy graphics rendering, hardware interaction such as Bluetooth, or long periods of offline work, native or hybrid approaches should be prioritized.

    Security also needs attention when generating HTML. Model output and user input should both be treated as untrusted data and must be escaped before being inserted into the page. Do not concatenate model output directly into the page, and do not include external scripts of unknown origin in the page.

    Connection layer: integrating tools with MCP

    The Model Context Protocol (MCP) was proposed by Anthropic in 2024. It is an open specification based on JSON-RPC 2.0. It defines the message format between a client (usually an AI application or agent host) and a server (a process that wraps specific tools). A server can declare three types of capabilities: tools, resources, and prompt templates. This article only discusses tools.

    Tool invocation mainly uses two methods. tools/list returns the names, descriptions, and JSON Schema for the input parameters of available tools. tools/call executes a specified tool and returns the result. A complete invocation data flow is as follows: the user makes a request, the model decides to call a tool, the client sends tools/call to the server, the server accesses the internal system and returns the result, and the result is passed back to the model for continued reasoning.

    Local scenarios usually use the stdio transport, while remote scenarios use the Streamable HTTP transport. Protocol versions should follow the latest revision of the official specification. Before integration, verify the transports and authentication requirements supported by the current version. Below is a minimal server example for a read-only query tool, using the official Python SDK.

    1. from mcp.server.fastmcp import FastMCP
    2. mcp = FastMCP("order-demo")
    3. @mcp.tool()
    4. def get_order_status(order_id: str) -> dict:
    5. """Query status by order ID; read-only operation."""
    6. # In a real project, call the internal API here and read secrets from environment variables
    7. return {"order_id": order_id, "status": "shipped"}
    8. if __name__ == "__main__":
    9. mcp.run(transport="stdio")

    The client configuration uses the common MCP client JSON format as an example:

    1. {
    2. "mcpServers": {
    3. "order-demo": {
    4. "command": "python",
    5. "args": ["server.py"]
    6. }
    7. }
    8. }

    Access tokens should not be written into configuration files or code. Set ORDER_API_TOKEN in the startup environment, and have the server read it via os.environ.

    Permission design needs to be tiered. Read-only tools (such as queries) and write tools (such as placing orders, refunds, and deletions) should be registered separately, and write tools should require human confirmation by default. For remote deployment, use authorization mechanisms such as OAuth, set short token lifetimes, and limit the accessible scope.

    The connection layer checklist is as follows.

    • Each tool exposes only the minimum parameters required to complete the task.
    • Tool descriptions are reviewed by the team. Tool descriptions and returned content also enter the model context, and malicious content may induce the model to make unauthorized calls, which is known as tool poisoning.
    • All calls are written to audit logs, recording the caller, parameter summary, and execution status.
    • Sensitive parameters such as phone numbers and ID numbers are masked in logs.
    • Write tools have rate limits.

    Skill packaging: definitions, templates, and governance

    A skill is an encapsulation of a set of validated multi-step processes. A single function call is an atomic operation, while a skill contains multiple steps, conditional logic, and acceptance criteria. Packaging provides three benefits. First, validated paths are fixed, so outputs for the same task are more stable. Second, high-level planning only needs to select skills, reducing the overhead of replanning each time. Third, team experience can be versioned, shared, and reused like code.

    Skill formats differ across platforms. The template below is an internal team format. It is recommended to manage it in the version repository together with code.

    1. name: dashboard-generate
    2. version: 1.2.0
    3. owner: data-team
    4. description: Generate a read-only data dashboard page from a specified data table
    5. inputs:
    6. - name: table_id
    7. type: string
    8. required: true
    9. - name: date_range
    10. type: string
    11. default: last_30_days
    12. outputs:
    13. - name: html_page
    14. type: string
    15. description: Escaped complete HTML
    16. steps:
    17. - Read the table schema (call schema_read, read-only)
    18. - Identify time, dimension, and metric fields
    19. - Run an aggregate query (call query_run, limit returned rows)
    20. - Select chart types and generate HTML
    21. required_tools: [schema_read, query_run]
    22. permissions: [data:read]
    23. acceptance:
    24. - The same input executed twice yields consistent metric values
    25. - A single execution takes less than 30 seconds
    26. - The page does not reference external scripts
    27. rollback: Revert to the previous version that passed acceptance

    Skills need a clear owner, version number, acceptance cases, and rollback method. Recommended metrics to track include task success rate, average duration, manual correction ratio, and rollback count. If a skill has not been called for a long time, or the underlying data table schema changes, it should be marked for review to prevent it from becoming stale.