SuperAPI AI Directory

askit

askit-mcp** is a flexible asyncio Python library and CLI tool that allows various LLM models to extend their abilities by invoking services from Model Context Protocol (MCP) servers and by calling locally-defined Python functions..

Open website

About this tool

AskIt is a flexible asyncio Python library and CLI tool designed to allow various LLM models to extend their own capabilities by calling the services of Model Context Protocol (MCP) servers, as well as by calling locally defined Python functions. The project is licensed under the Apache License 2.0.

Key Features

  • Simple and lightweight
  • Can connect to multiple MCP servers simultaneously
  • Supports STDIO, SSE, and Streamable-HTTP types of MCP servers
  • Supports tool use/function calling for MCP servers written in any language
  • Supports tool use/function calling for locally defined Python functions
  • Supports multiple LLM providers: currently supports OpenAI and XAI (Grok), with Anthropic, Ollama, and LMStudio support coming soon
  • Optional support for streaming LLM responses
  • Securely stores API keys via environment variables

Installation

Using AskIt MCP requires Python 3.11+ to be installed on the system. Using a Python version manager is recommended. The package can then be installed via pip.

AskIt CLI Quick Start

The easiest way to use AskIt is through its integrated command-line interface (CLI) tool. The CLI allows users to interact with MCP servers and LLMs using natural language queries, making it easy to access and manipulate data from various sources.

The following command will use the default OpenAI model (gpt-4o-mini) to enter a "chat-eval" loop with the configured LLM. Simply provide the OpenAI API key as a command-line argument.

The OpenAI API key can also be provided as a provider-specific environment variable.

Different models or providers can be specified using command-line options. For example, using the XAI provider (Grok) and a specific model. The XAI API key needs to be provided as an environment variable or command-line argument.

More information about provider-specific environment variables can be found in the project documentation.

Connecting MCP Servers to AskIt

Multiple MCP servers can be connected by creating an mcp_config.json file in the current working directory. This file should contain the MCP servers to connect toConfiguration. The AskIt CLI will automatically load this configuration and connect to the specified MCP servers.

A sample file, mcp_config.json.example, is provided in the repository root for reference. You can copy this file to mcp_config.json and modify it as needed.

You can add any number of MCP servers; the client will connect to all of them and provide their tools to the configured LLM. AskIt supports two main types of MCP servers: stdio and Streamable HTTP. The former is used for MCP servers located on the local machine, while the latter can be used to access remotely hosted MCP servers.

Many third-party MCP servers are available; a good list can be found in the Model Context Protocol Servers repository or the Awesome MCP Servers repository.

Once you have set up some MCP servers and they are running, you can start the AskIt CLI, and it will automatically connect to the configured MCP servers. You can then start the CLI as in the previous section, but at this point the LLM will be able to interact with the configured MCP servers.

API Quick Start

You can also use AskIt as a Python library in your own applications. Below is a simple example of programmatic usage; see example_simple.py.

MCP Servers and the API

You can also use the AskIt API to connect MCP servers. Simply add a call to await askit.load_mcp_config(), as shown in the following example. This will load MCP servers from the mcp_config.json file in the current working directory and provide their tools to the configured LLM.

Function Calling with the API

With AskIt, you can easily give the LLM direct access to custom Python functions you write (without the hassle of creating an MCP server). Simply define the functions as described below and pass them in via the tools parameter of the prompt method. The LLM can then call these functions as needed. In this quick example, we define a function that returns the current time and make it available to the configured LLM. The LLM can call this function to get the current time. You can pass in any number of functions, and the LLM will be able to call them as needed.

Please note that the functionType annotations and docstrings on numbers. LLMs use them to understand how to call functions and what functions return. See example_simple_with_functions.py.

The AskIt API is designed to be simple and easy to use. The main class is AskIt, which provides methods for interacting with LLMs and MCP servers.

If no arguments are provided, the AskIt instance will use default values from the provided environment variables. Custom system prompts, models, API keys, base URLs, and providers can also be passed in.

The default model for the OpenAI provider is gpt-4o-mini, and the default model for the XAI provider is grok-4-latest. These defaults can be overridden by passing in the model parameter.

For OPENAI, the list of currently supported models can be found here; for XAI (Grok), the list of currently supported models can be found here.

To prompt the LLM, you can use the askit.prompt() method. This method accepts a string prompt and returns the LLM's response.

This method sends the prompt to the configured LLM and returns the response. You can also provide a list of tools (functions) that the LLM can call, and specify whether to stream the response. The messages parameter can be used to provide a list of messages to be included in the prompt context. This is useful for maintaining conversation history or providing additional context to the LLM. The prompt method automatically appends the prompt and response to the provided messages list, making it easy to maintain conversation history across multiple calls to the prompt method. For a good example of how to use the messages parameter, see example_simple_chat.py.

If stream=True is passed in, the response will be an async generator that yields chunks as the response is received. This is useful for long-running prompts or when you want to display the response in real time. See example_streaming.py.

This method loads the MCP configuration from a JSON file. The configuration should contain the MCP servers to connect to, as described in the "Connecting MCP Servers to AskIt" section.

Other Examples

Other API examples matching the example_*.py pattern can be found in the repository root. These examples demonstrate various other use cases.

Environment Variables

AskIt MCP uses environment variables to securely store API keys and configuration settings. You can also use a standard .env file in the current workdirectory to set these environment variables. The AskIt CLI will automatically load environment variables from this file. For reference, a file named .env.example is provided in the repository root. You can copy this file to .env and modify it as needed.

General Environment Variables

  • ASKIT_SYSTEM_PROMPT - Optional, configures the default system prompt for AskIt
  • ASKIT_PROVIDER - Optional, configures the default provider for AskIt ["OPENAI", "XAI"], defaults to "OPENAI"

Provider-Specific Environment Variables

  • OPENAI_API_KEY - Specify your_openai_api_key_here for the OpenAI provider
  • OPENAI_BASE_URL - Optional, configures a different base URL for the OpenAI provider
  • OPENAI_MODEL - Optional, configures a different model for the OpenAI provider, defaults to "gpt-4o-mini"
  • XAI_API_KEY - Specify your_xai_api_key_here for the XAI provider
  • XAI_BASE_URL - Optional, configures a different base URL for the XAI provider
  • XAI_MODEL - Optional, configures a different model for the XAI provider, defaults to "grok-3-latest"

OpenAI API key (or the API key of another supported provider)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

Apache License 2.0